Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / libdispatch / serial-queue-norace.c
blob2b8009d38b2a2041e75dee18a3df739c86c44764
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() {
11 fprintf(stderr, "Hello world.\n");
12 dispatch_semaphore_t done = dispatch_semaphore_create(0);
14 dispatch_queue_t q1 = dispatch_queue_create("my.queue1", DISPATCH_QUEUE_CONCURRENT);
15 dispatch_queue_t q2 = dispatch_queue_create("my.queue2", DISPATCH_QUEUE_SERIAL);
17 global = 42;
18 for (int i = 0; i < 10; i++) {
19 dispatch_async(q1, ^{
20 for (int i = 0; i < 100; i++) {
21 dispatch_sync(q2, ^{
22 global++;
23 });
25 });
28 dispatch_barrier_async(q1, ^{
29 dispatch_semaphore_signal(done);
30 });
32 dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
33 fprintf(stderr, "Done.\n");
36 // CHECK: Hello world.
37 // CHECK: Done.