1 // RUN: %clang_tsan %s -o %t
2 // RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
4 #include "dispatch/dispatch.h"
10 fprintf(stderr
, "start\n");
11 dispatch_semaphore_t done
= dispatch_semaphore_create(0);
13 dispatch_queue_t background_q
= dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT
, 0);
14 dispatch_queue_t serial_q
= dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL
);
15 assert(background_q
!= serial_q
);
17 dispatch_async(background_q
, ^{
18 __block
long block_var
= 0;
20 dispatch_sync(serial_q
, ^{
24 fprintf(stderr
, "block_var = %ld\n", block_var
);
26 dispatch_semaphore_signal(done
);
29 dispatch_semaphore_wait(done
, DISPATCH_TIME_FOREVER
);
30 fprintf(stderr
, "done\n");
34 // CHECK: block_var = 42