PR c++/86342 - -Wdeprecated-copy and system headers.
[official-gcc.git] / libgo / misc / cgo / testsanitizers / src / tsan6.go
blobc96f08d2f3752f2165a1ee2700d56c08d75539ba
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.
5 package main
7 // Check that writes to Go allocated memory, with Go synchronization,
8 // do not look like a race.
11 #cgo CFLAGS: -fsanitize=thread
12 #cgo LDFLAGS: -fsanitize=thread
14 void f(char *p) {
15 *p = 1;
18 import "C"
20 import (
21 "runtime"
22 "sync"
25 func main() {
26 var wg sync.WaitGroup
27 var mu sync.Mutex
28 c := make(chan []C.char, 100)
29 for i := 0; i < 10; i++ {
30 wg.Add(2)
31 go func() {
32 defer wg.Done()
33 for i := 0; i < 100; i++ {
34 c <- make([]C.char, 4096)
35 runtime.Gosched()
37 }()
38 go func() {
39 defer wg.Done()
40 for i := 0; i < 100; i++ {
41 p := &(<-c)[0]
42 mu.Lock()
43 C.f(p)
44 mu.Unlock()
46 }()
48 wg.Wait()