1 // Copyright 2016 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 main 6 7 // Check that calls to C.malloc/C.free do not trigger TSAN false 8 // positive reports. 9 10 // #cgo CFLAGS: -fsanitize=thread 11 // #cgo LDFLAGS: -fsanitize=thread 12 // #include <stdlib.h> 13 import "C" 14 15 import ( 16 "runtime" 17 "sync" 18 ) 19 20 func main() { 21 var wg sync.WaitGroup 22 for i := 0; i < 10; i++ { 23 wg.Add(1) 24 go func() { 25 defer wg.Done() 26 for i := 0; i < 100; i++ { 27 p := C.malloc(C.size_t(i * 10)) 28 runtime.Gosched() 29 C.free(p) 30 } 31 }() 32 } 33 wg.Wait() 34 } 35