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 dispatch_semaphore_t sem
;
13 void callback(void *context
) {
15 barrier_wait(&barrier
);
17 dispatch_semaphore_signal(sem
);
21 fprintf(stderr
, "Hello world.\n");
22 barrier_init(&barrier
, 2);
24 dispatch_queue_t q
= dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT
);
25 dispatch_group_t g
= dispatch_group_create();
26 sem
= dispatch_semaphore_create(0);
28 dispatch_group_enter(g
);
31 dispatch_group_leave(g
);
32 barrier_wait(&barrier
);
34 dispatch_group_notify(g
, q
, ^{
36 barrier_wait(&barrier
);
38 dispatch_semaphore_signal(sem
);
40 dispatch_semaphore_wait(sem
, DISPATCH_TIME_FOREVER
);
42 dispatch_group_enter(g
);
45 dispatch_group_leave(g
);
46 barrier_wait(&barrier
);
48 dispatch_group_notify_f(g
, q
, NULL
, &callback
);
49 dispatch_semaphore_wait(sem
, DISPATCH_TIME_FOREVER
);
51 fprintf(stderr
, "Done.\n");
54 // CHECK: Hello world.