Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / libdispatch / source-serial.c
blob3f22c44046a0e006db6d69e4d89a205d9f593f3e
1 // RUN: %clang_tsan %s -o %t
2 // RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
4 #include <dispatch/dispatch.h>
6 #include <stdio.h>
8 long global;
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");
21 global++;
23 if (global > 50) {
24 dispatch_semaphore_signal(sem);
25 dispatch_suspend(timer);
27 });
28 dispatch_resume(timer);
30 dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
32 fprintf(stderr, "Done.\n");
35 // CHECK: Hello world.
36 // CHECK: timer
37 // CHECK: Done.
38 // CHECK-NOT: timer