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 | dispatch_semaphore_t done; |
10 | |
11 | void handler(void *arg) { |
12 | fprintf(stderr, format: "global = %ld\n" , global); |
13 | |
14 | dispatch_semaphore_signal(done); |
15 | } |
16 | |
17 | int main(int argc, const char *argv[]) { |
18 | done = dispatch_semaphore_create(0); |
19 | |
20 | dispatch_queue_t queue = |
21 | dispatch_queue_create("my.queue" , DISPATCH_QUEUE_CONCURRENT); |
22 | |
23 | dispatch_source_t source = |
24 | dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGHUP, 0, queue); |
25 | |
26 | global = 42; |
27 | |
28 | dispatch_source_set_registration_handler_f(source, handler); |
29 | |
30 | dispatch_resume(source); |
31 | |
32 | dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER); |
33 | |
34 | return 0; |
35 | } |
36 | |
37 | // CHECK: global = 42 |
38 | |