Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / libdispatch / apply-race.c
blob10e954c2300c2d2510aec57135b3dbc71f4108ba
1 // RUN: %clang_tsan %s -o %t
2 // RUN: %deflake %run %t 2>&1 | FileCheck %s
4 #include <dispatch/dispatch.h>
6 #include "../test.h"
8 long global;
10 int main(int argc, const char *argv[]) {
11 barrier_init(&barrier, 2);
12 fprintf(stderr, "start\n");
14 // Warm up GCD (workaround for macOS Sierra where dispatch_apply might run single-threaded).
15 dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ });
17 dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
18 dispatch_apply(2, q, ^(size_t i) {
19 global = i;
20 barrier_wait(&barrier);
21 });
23 fprintf(stderr, "done\n");
24 return 0;
27 // CHECK: start
28 // CHECK: WARNING: ThreadSanitizer: data race
29 // CHECK: Location is global 'global'
30 // CHECK: done