1 // RUN: %clang_tsan %s -o %t
2 // RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
4 #include <dispatch/dispatch.h>
8 static const long kNumThreads
= 4;
13 static dispatch_once_t once_token
;
14 static dispatch_once_t once_token2
;
21 void *Thread(void *a
) {
22 barrier_wait(&barrier
);
24 dispatch_once(&once_token
, ^{
30 dispatch_once_f(&once_token2
, NULL
, f
);
33 fprintf(stderr
, "global = %ld\n", x
);
34 fprintf(stderr
, "global2 = %ld\n", x2
);
39 fprintf(stderr
, "Hello world.\n");
40 barrier_init(&barrier
, kNumThreads
);
42 pthread_t t
[kNumThreads
];
43 for (int i
= 0; i
< kNumThreads
; i
++) {
44 pthread_create(&t
[i
], 0, Thread
, 0);
46 for (int i
= 0; i
< kNumThreads
; i
++) {
47 pthread_join(t
[i
], 0);
50 fprintf(stderr
, "Done.\n");
53 // CHECK: Hello world.