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
main(int argc,const char * argv[])10 int main(int argc, const char *argv[]) {
11 dispatch_semaphore_t done = dispatch_semaphore_create(0);
12 dispatch_queue_t target_queue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
13 dispatch_queue_t q1 = dispatch_queue_create(NULL, DISPATCH_QUEUE_CONCURRENT);
14 dispatch_queue_t q2 = dispatch_queue_create(NULL, DISPATCH_QUEUE_CONCURRENT);
15 dispatch_set_target_queue(q1, target_queue);
16 dispatch_set_target_queue(q2, target_queue);
17
18 for (int i = 0; i < 100000; i++) {
19 dispatch_async(q1, ^{
20 global++;
21
22 if (global == 200000) {
23 dispatch_semaphore_signal(done);
24 }
25 });
26 dispatch_async(q2, ^{
27 global++;
28
29 if (global == 200000) {
30 dispatch_semaphore_signal(done);
31 }
32 });
33 }
34
35 dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
36 fprintf(stderr, "Done.\n");
37 return 0;
38 }
39
40 // CHECK: Done.
41