Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / libdispatch / suspend.c
blob617ad917e2a64373fda87461dd57e96d4ecb64b7
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 my_global = 0;
10 int main(int argc, const char *argv[]) {
11 fprintf(stderr, "Hello world.\n");
13 dispatch_queue_t q1 = dispatch_queue_create("queue1", NULL);
14 dispatch_queue_t q2 = dispatch_queue_create("queue2", NULL);
15 dispatch_group_t g = dispatch_group_create();
17 dispatch_sync(q1, ^{
18 dispatch_suspend(q1);
19 dispatch_async(q2, ^{
20 my_global++;
21 dispatch_resume(q1);
22 });
23 });
25 dispatch_sync(q1, ^{
26 my_global++;
27 });
29 dispatch_sync(q1, ^{
30 dispatch_suspend(q1);
31 dispatch_group_enter(g);
32 dispatch_async(q1,^{ my_global++; });
33 dispatch_async(q1,^{ my_global++; });
34 dispatch_async(q1,^{ my_global++; dispatch_group_leave(g); });
35 my_global++;
36 dispatch_resume(q1);
37 });
39 dispatch_group_wait(g, DISPATCH_TIME_FOREVER);
41 fprintf(stderr, "Done.\n");
42 return 0;
45 // CHECK: Hello world.
46 // CHECK: Done.