1 // RUN: %clang_tsan %s -o %t
2 // RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
4 #include <dispatch/dispatch.h>
9 dispatch_queue_t queue
;
11 dispatch_semaphore_t sem
;
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");
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
, ^{
35 dispatch_io_barrier(channel
, ^{
38 dispatch_semaphore_signal(sem
);
41 dispatch_semaphore_wait(sem
, DISPATCH_TIME_FOREVER
);
42 dispatch_io_close(channel
, 0);
44 fprintf(stderr
, "Done.\n");
48 // CHECK: Hello world.