1 // RUN: %clang_tsan %s -o %t
2 // RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
4 #include <dispatch/dispatch.h>
10 int main(int argc
, const char *argv
[]) {
11 fprintf(stderr
, "Hello world.\n");
13 dispatch_queue_t q
= dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL
);
14 dispatch_source_t timer
= dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER
, 0, 0, q
);
15 long long interval_ms
= 10;
16 dispatch_source_set_timer(timer
, dispatch_time(DISPATCH_TIME_NOW
, 0), interval_ms
* NSEC_PER_MSEC
, 0);
18 dispatch_semaphore_t sem
= dispatch_semaphore_create(0);
19 dispatch_source_set_event_handler(timer
, ^{
20 fprintf(stderr
, "timer\n");
24 dispatch_semaphore_signal(sem
);
25 dispatch_suspend(timer
);
28 dispatch_resume(timer
);
30 dispatch_semaphore_wait(sem
, DISPATCH_TIME_FOREVER
);
32 fprintf(stderr
, "Done.\n");
35 // CHECK: Hello world.