github.com/MangoDowner/go-gm@v0.0.0-20180818020936-8baa2bd4408c/misc/cgo/test/issue3775.go (about) 1 // +build !android 2 3 package cgotest 4 5 /* 6 void lockOSThreadCallback(void); 7 inline static void lockOSThreadC(void) 8 { 9 lockOSThreadCallback(); 10 } 11 int usleep(unsigned usec); 12 */ 13 import "C" 14 15 import ( 16 "runtime" 17 "testing" 18 ) 19 20 func init() { 21 // Same as test3775 but run during init so that 22 // there are two levels of internal runtime lock 23 // (1 for init, 1 for cgo). 24 // This would have been broken by CL 11663043. 25 C.lockOSThreadC() 26 } 27 28 func test3775(t *testing.T) { 29 // Used to panic because of the UnlockOSThread below. 30 C.lockOSThreadC() 31 } 32 33 //export lockOSThreadCallback 34 func lockOSThreadCallback() { 35 runtime.LockOSThread() 36 runtime.UnlockOSThread() 37 go C.usleep(10000) 38 runtime.Gosched() 39 }