mirror of
https://github.com/golang/go
synced 2024-11-23 07:50:05 -07:00
42c51debe8
For #15919 Change-Id: I9fc38d9c8a9cc9406b551315e1599750fe212d0d Reviewed-on: https://go-review.googlesource.com/23635 Reviewed-by: David Crawshaw <crawshaw@golang.org> Run-TryBot: Elias Naur <elias.naur@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
45 lines
760 B
Go
45 lines
760 B
Go
// Copyright 2013 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package cgotest
|
|
|
|
// extern void doAdd(int, int);
|
|
import "C"
|
|
|
|
import (
|
|
"runtime"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
var sum struct {
|
|
sync.Mutex
|
|
i int
|
|
}
|
|
|
|
//export Add
|
|
func Add(x int) {
|
|
defer func() {
|
|
recover()
|
|
}()
|
|
sum.Lock()
|
|
sum.i += x
|
|
sum.Unlock()
|
|
var p *int
|
|
*p = 2
|
|
}
|
|
|
|
func testCthread(t *testing.T) {
|
|
if runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") {
|
|
t.Skip("the iOS exec wrapper is unable to properly handle the panic from Add")
|
|
}
|
|
sum.i = 0
|
|
C.doAdd(10, 6)
|
|
|
|
want := 10 * (10 - 1) / 2 * 6
|
|
if sum.i != want {
|
|
t.Fatalf("sum=%d, want %d", sum.i, want)
|
|
}
|
|
}
|