1 // RUN: %clang_tsan %s -o %t
2 // RUN: %deflake %run %t 2>&1 | FileCheck %s
4 #include <dispatch/dispatch.h>
10 int main(int argc
, const char *argv
[]) {
11 barrier_init(&barrier
, 2);
12 fprintf(stderr
, "start\n");
14 // Warm up GCD (workaround for macOS Sierra where dispatch_apply might run single-threaded).
15 dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT
, 0), ^{ });
17 dispatch_queue_t q
= dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT
);
18 dispatch_apply(2, q
, ^(size_t i
) {
20 barrier_wait(&barrier
);
23 fprintf(stderr
, "done\n");
28 // CHECK: WARNING: ThreadSanitizer: data race
29 // CHECK: Location is global 'global'