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 global;
9
10int main() {
11 fprintf(stderr, format: "Hello world.\n");
12 dispatch_semaphore_t done = dispatch_semaphore_create(0);
13
14 dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
15 global = 42;
16
17 dispatch_group_t g = dispatch_group_create();
18 dispatch_group_async(g, q, ^{
19 global = 43;
20 });
21 dispatch_group_wait(g, DISPATCH_TIME_FOREVER);
22
23 global = 44;
24
25 dispatch_group_enter(g);
26 dispatch_async(q, ^{
27 global = 45;
28 dispatch_group_leave(g);
29 });
30 dispatch_group_wait(g, DISPATCH_TIME_FOREVER);
31
32 global = 46;
33
34 dispatch_group_enter(g);
35 dispatch_async(q, ^{
36 global = 47;
37 dispatch_group_leave(g);
38 });
39 dispatch_group_notify(g, q, ^{
40 global = 48;
41
42 dispatch_semaphore_signal(done);
43 });
44
45 dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
46 fprintf(stderr, format: "Done.\n");
47}
48
49// CHECK: Hello world.
50// CHECK: Done.
51

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