Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / libdispatch / source-cancel.c
bloba85de9511b23cf58f5fdfec8a546220ab1cd4083
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 dispatch_semaphore_t done = dispatch_semaphore_create(0);
13 dispatch_queue_t queue =
14 dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
16 dispatch_source_t source =
17 dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
19 dispatch_source_set_timer(source, dispatch_walltime(NULL, 0), 1e9, 5);
21 global = 42;
23 dispatch_source_set_cancel_handler(source, ^{
24 fprintf(stderr, "global = %ld\n", global);
26 dispatch_semaphore_signal(done);
27 });
29 dispatch_resume(source);
30 dispatch_cancel(source);
32 dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
34 return 0;
37 // CHECK: global = 42