Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / libdispatch / blocks.c
blobe8f1e28efbe103e40c0e014caca90ae4ac020bd5
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>
7 #include <assert.h>
9 int main() {
10 fprintf(stderr, "start\n");
11 dispatch_semaphore_t done = dispatch_semaphore_create(0);
13 dispatch_queue_t background_q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
14 dispatch_queue_t serial_q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL);
15 assert(background_q != serial_q);
17 dispatch_async(background_q, ^{
18 __block long block_var = 0;
20 dispatch_sync(serial_q, ^{
21 block_var = 42;
22 });
24 fprintf(stderr, "block_var = %ld\n", block_var);
26 dispatch_semaphore_signal(done);
27 });
29 dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
30 fprintf(stderr, "done\n");
33 // CHECK: start
34 // CHECK: block_var = 42
35 // CHECK: done