1
2
3
4
5
6
7 package cgotest
8
9
20 import "C"
21
22 import (
23 "runtime"
24 "testing"
25 "time"
26 )
27
28
29 func Gosched() {
30 runtime.Gosched()
31 }
32
33 func init() {
34 testThreadLockFunc = testThreadLock
35 }
36
37 func testThreadLock(t *testing.T) {
38 stop := make(chan int)
39 go func() {
40
41
42 for {
43 select {
44 case <-stop:
45 return
46 case <-time.After(time.Millisecond * 100):
47 }
48 }
49 }()
50 defer close(stop)
51
52 for i := 0; i < 1000; i++ {
53 if !C.Ctid() {
54 t.Fatalf("cgo has not locked OS thread")
55 }
56 }
57 }
58
View as plain text