summaryrefslogtreecommitdiff
path: root/misc/cgo/testtls/tls.go
diff options
context:
space:
mode:
Diffstat (limited to 'misc/cgo/testtls/tls.go')
-rw-r--r--misc/cgo/testtls/tls.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/misc/cgo/testtls/tls.go b/misc/cgo/testtls/tls.go
new file mode 100644
index 000000000..a9546a61c
--- /dev/null
+++ b/misc/cgo/testtls/tls.go
@@ -0,0 +1,28 @@
+// 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 cgotlstest
+
+// #include <pthread.h>
+// extern void setTLS(int);
+// extern int getTLS();
+import "C"
+
+import (
+ "runtime"
+ "testing"
+)
+
+func testTLS(t *testing.T) {
+ var keyVal C.int = 1234
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+ C.setTLS(C.int(keyVal))
+ storedVal := C.getTLS()
+
+ if storedVal != keyVal {
+ t.Fatalf("stored %d want %d", storedVal, keyVal)
+ }
+}