github.com/varialus/godfly@v0.0.0-20130904042352-1934f9f095ab/misc/cgo/testtls/tls.go (about) 1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package cgotlstest 6 7 // #include <pthread.h> 8 // extern void setTLS(int); 9 // extern int getTLS(); 10 import "C" 11 12 import ( 13 "runtime" 14 "testing" 15 ) 16 17 func testTLS(t *testing.T) { 18 var keyVal C.int = 1234 19 20 runtime.LockOSThread() 21 defer runtime.UnlockOSThread() 22 C.setTLS(C.int(keyVal)) 23 storedVal := C.getTLS() 24 25 if storedVal != keyVal { 26 t.Fatalf("stored %d want %d", storedVal, keyVal) 27 } 28 }