Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / libdispatch / io-barrier.c
blobc0d3fb0cf6fe95ec1682b58e3d4c87dab4e8994d
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>
7 #include <stdlib.h>
9 dispatch_queue_t queue;
10 dispatch_data_t data;
11 dispatch_semaphore_t sem;
12 const char *path;
14 long my_global = 0;
16 int main(int argc, const char *argv[]) {
17 fprintf(stderr, "Hello world.\n");
19 queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
20 sem = dispatch_semaphore_create(0);
21 path = tempnam(NULL, "libdispatch-io-barrier");
22 char buf[1000];
23 data = dispatch_data_create(buf, sizeof(buf), NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
25 dispatch_io_t channel = dispatch_io_create_with_path(DISPATCH_IO_STREAM, path, O_CREAT | O_WRONLY, 0666, queue, ^(int error) { });
26 if (! channel) abort();
27 dispatch_io_set_high_water(channel, 1);
29 for (int i = 0; i < 1000; i++) {
30 dispatch_io_barrier(channel, ^{
31 my_global = 42;
32 });
35 dispatch_io_barrier(channel, ^{
36 my_global = 43;
38 dispatch_semaphore_signal(sem);
39 });
41 dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
42 dispatch_io_close(channel, 0);
44 fprintf(stderr, "Done.\n");
45 return 0;
48 // CHECK: Hello world.
49 // CHECK: Done.