...

Source file src/cmd/cgo/internal/testsanitizers/testdata/tsan3.go

Documentation: cmd/cgo/internal/testsanitizers/testdata

     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  // The stubs for the C functions read and write the same slot on the
     8  // g0 stack when copying arguments in and out.
     9  
    10  /*
    11  #cgo CFLAGS: -fsanitize=thread
    12  #cgo LDFLAGS: -fsanitize=thread
    13  
    14  int Func1() {
    15  	return 0;
    16  }
    17  
    18  void Func2(int x) {
    19  	(void)x;
    20  }
    21  */
    22  import "C"
    23  
    24  func main() {
    25  	const N = 10000
    26  	done := make(chan bool, N)
    27  	for i := 0; i < N; i++ {
    28  		go func() {
    29  			C.Func1()
    30  			done <- true
    31  		}()
    32  		go func() {
    33  			C.Func2(0)
    34  			done <- true
    35  		}()
    36  	}
    37  	for i := 0; i < 2*N; i++ {
    38  		<-done
    39  	}
    40  }
    41  

View as plain text