1// RUN: %clang_tsan %s -o %t
2// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
3
4#include <dispatch/dispatch.h>
5
6#include <stdio.h>
7
8long my_global = 0;
9
10int main(int argc, const char *argv[]) {
11 fprintf(stderr, format: "Hello world.\n");
12
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();
16
17 dispatch_sync(q1, ^{
18 dispatch_suspend(q1);
19 dispatch_async(q2, ^{
20 my_global++;
21 dispatch_resume(q1);
22 });
23 });
24
25 dispatch_sync(q1, ^{
26 my_global++;
27 });
28
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 });
38
39 dispatch_group_wait(g, DISPATCH_TIME_FOREVER);
40
41 fprintf(stderr, format: "Done.\n");
42 return 0;
43}
44
45// CHECK: Hello world.
46// CHECK: Done.
47

source code of compiler-rt/test/tsan/libdispatch/suspend.c