Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / libdispatch / groups-leave.c
blobf63d6e5f57fb228f8782f46953c83fe86ef2e799
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 "../test.h"
8 dispatch_semaphore_t sem;
10 long global;
11 long global2;
13 void callback(void *context) {
14 global2 = 48;
15 barrier_wait(&barrier);
17 dispatch_semaphore_signal(sem);
20 int main() {
21 fprintf(stderr, "Hello world.\n");
22 barrier_init(&barrier, 2);
24 dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
25 dispatch_group_t g = dispatch_group_create();
26 sem = dispatch_semaphore_create(0);
28 dispatch_group_enter(g);
29 dispatch_async(q, ^{
30 global = 47;
31 dispatch_group_leave(g);
32 barrier_wait(&barrier);
33 });
34 dispatch_group_notify(g, q, ^{
35 global = 48;
36 barrier_wait(&barrier);
38 dispatch_semaphore_signal(sem);
39 });
40 dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
42 dispatch_group_enter(g);
43 dispatch_async(q, ^{
44 global2 = 47;
45 dispatch_group_leave(g);
46 barrier_wait(&barrier);
47 });
48 dispatch_group_notify_f(g, q, NULL, &callback);
49 dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
51 fprintf(stderr, "Done.\n");
54 // CHECK: Hello world.
55 // CHECK: Done.