tsan3.go 662 B

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