summaryrefslogtreecommitdiff
path: root/misc/cgo/testtls/tls.go
blob: a9546a61c23bd163f415ba1eb258245f104e0b39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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)
	}
}