1 // Copyright 2023 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.
7 // This program failed when run under the C/C++ ThreadSanitizer.
8 // There was no TSAN synchronization for the call to the cgo
12 #cgo CFLAGS: -g -fsanitize=thread
13 #cgo LDFLAGS: -g -fsanitize=thread
28 void tsanTraceback(struct tracebackArg *arg) {
32 static void* spin(void *arg) {
34 struct timeval tvstart, tvnow;
40 gettimeofday(&tvstart, NULL);
41 for (n = 0; n < 1<<20; n++) {
46 gettimeofday(&tvnow, NULL);
47 diff = (tvnow.tv_sec - tvstart.tv_sec) * 1000 * 1000 + (tvnow.tv_usec - tvstart.tv_usec);
49 // Profile frequency is 100Hz so we should definitely
50 // get some signals in 50 milliseconds.
51 if (diff > 50 * 1000) {
61 static void runThreads(int n) {
68 for (i = 0; i < n; i++) {
69 pthread_create(&ids[i], NULL, spin, NULL);
71 for (i = 0; i < n; i++) {
72 pthread_join(ids[i], NULL);
86 runtime.SetCgoTraceback(0, unsafe.Pointer(C.tsanTraceback), nil, nil)
87 pprof.StartCPUProfile(io.Discard)
88 C.runThreads(C.int(runtime.GOMAXPROCS(0)))
89 pprof.StopCPUProfile()