1
0
mirror of https://github.com/golang/go synced 2024-11-22 15:24:42 -07:00
go/misc/cgo/test/issue3775.go
Russ Cox 4d17efe81b misc/cgo/test: test recursive internal OS thread lock
This would have failed with CL 11663043.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/11480045
2013-07-23 14:43:55 -04:00

38 lines
674 B
Go

package cgotest
/*
void lockOSThreadCallback(void);
inline static void lockOSThreadC(void)
{
lockOSThreadCallback();
}
int usleep(unsigned usec);
*/
import "C"
import (
"runtime"
"testing"
)
func init() {
// Same as test3775 but run during init so that
// there are two levels of internal runtime lock
// (1 for init, 1 for cgo).
// This would have been broken by CL 11663043.
C.lockOSThreadC()
}
func test3775(t *testing.T) {
// Used to panic because of the UnlockOSThread below.
C.lockOSThreadC()
}
//export lockOSThreadCallback
func lockOSThreadCallback() {
runtime.LockOSThread()
runtime.UnlockOSThread()
go C.usleep(10000)
runtime.Gosched()
}