1 | // RUN: %clang_tsan %s -o %t |
2 | // RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer' |
3 | |
4 | #include "dispatch/dispatch.h" |
5 | |
6 | #include <stdio.h> |
7 | |
8 | long global; |
9 | |
10 | int main() { |
11 | fprintf(stderr, format: "Hello world.\n" ); |
12 | dispatch_semaphore_t done = dispatch_semaphore_create(0); |
13 | |
14 | dispatch_queue_t q1 = dispatch_queue_create("my.queue1" , DISPATCH_QUEUE_CONCURRENT); |
15 | dispatch_queue_t q2 = dispatch_queue_create("my.queue2" , DISPATCH_QUEUE_SERIAL); |
16 | |
17 | global = 42; |
18 | for (int i = 0; i < 10; i++) { |
19 | dispatch_async(q1, ^{ |
20 | for (int i = 0; i < 100; i++) { |
21 | dispatch_sync(q2, ^{ |
22 | global++; |
23 | }); |
24 | } |
25 | }); |
26 | } |
27 | |
28 | dispatch_barrier_async(q1, ^{ |
29 | dispatch_semaphore_signal(done); |
30 | }); |
31 | |
32 | dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER); |
33 | fprintf(stderr, format: "Done.\n" ); |
34 | } |
35 | |
36 | // CHECK: Hello world. |
37 | // CHECK: Done. |
38 | |