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 15int val; 16 17int getVal() { 18 return val; 19} 20 21void setVal(int i) { 22 val = i; 23} 24*/ 25import "C" 26 27import ( 28 "runtime" 29) 30 31func main() { 32 runtime.LockOSThread() 33 C.setVal(1) 34 c := make(chan bool) 35 go func() { 36 runtime.LockOSThread() 37 C.setVal(2) 38 c <- true 39 }() 40 <-c 41 if v := C.getVal(); v != 2 { 42 panic(v) 43 } 44} 45