1 // RUN: %clang_tsan %s -o %t
2 // RUN: %run %t 2>&1 | FileCheck %s
3 
4 // TODO(yln): fails on one of our bots, need to investigate
5 // REQUIRES: disabled
6 
7 #include <dispatch/dispatch.h>
8 
9 #include <stdio.h>
10 
11 long global;
12 
13 int main(int argc, const char *argv[]) {
14   fprintf(stderr, "Hello world.\n");
15 
16   dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL);
17   dispatch_semaphore_t sem = dispatch_semaphore_create(0);
18 
19   global = 44;
20   dispatch_data_t data = dispatch_data_create("buffer", 6, q, ^{
21     fprintf(stderr, "Data destructor.\n");
22     global++;
23 
24     dispatch_semaphore_signal(sem);
25   });
26   dispatch_release(data);
27   data = NULL;
28 
29   dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
30 
31   data = dispatch_data_create("buffer", 6, q, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
32   dispatch_release(data);
33   data = NULL;
34 
35   fprintf(stderr, "Done.\n");
36 }
37 
38 // CHECK: Hello world.
39 // CHECK: Data destructor.
40 // CHECK-NOT: WARNING: ThreadSanitizer
41 // CHECK: Done.
42