xref: /llvm-project/compiler-rt/test/tsan/libdispatch/source-registration.c (revision a59dad920ffb7a01f8e275ac4b6596048621fd20)
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 
13   dispatch_queue_t queue =
14       dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
15 
16   dispatch_source_t source =
17       dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGHUP, 0, queue);
18 
19   global = 42;
20 
21   dispatch_source_set_registration_handler(source, ^{
22     fprintf(stderr, "global = %ld\n", global);
23 
24     dispatch_semaphore_signal(done);
25   });
26 
27   dispatch_resume(source);
28 
29   dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
30 
31   return 0;
32 }
33 
34 // CHECK: global = 42
35