• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2015 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
5package main
6
7// This program produced false race reports when run under the C/C++
8// ThreadSanitizer, as it did not understand the synchronization in
9// the Go code.
10
11/*
12#cgo CFLAGS: -fsanitize=thread
13#cgo LDFLAGS: -fsanitize=thread
14
15extern void GoRun(void);
16
17// Yes, you can have definitions if you use //export, as long as they are weak.
18
19int val __attribute__ ((weak));
20
21int run(void) __attribute__ ((weak));
22
23int run() {
24	val = 1;
25	GoRun();
26	return val;
27}
28
29void setVal(int) __attribute__ ((weak));
30
31void setVal(int i) {
32	val = i;
33}
34*/
35import "C"
36
37import "runtime"
38
39//export GoRun
40func GoRun() {
41	runtime.LockOSThread()
42	c := make(chan bool)
43	go func() {
44		runtime.LockOSThread()
45		C.setVal(2)
46		c <- true
47	}()
48	<-c
49}
50
51func main() {
52	if v := C.run(); v != 2 {
53		panic(v)
54	}
55}
56