1 // RUN: %clang_tsan %s -o %t
2 // RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
4 #include <dispatch/dispatch.h>
11 int main(int argc
, const char *argv
[]) {
12 fprintf(stderr
, "Hello world.\n");
14 dispatch_queue_t queue
= dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT
);
15 dispatch_semaphore_t sem
= dispatch_semaphore_create(0);
16 const char *path
= tempnam(NULL
, "libdispatch-io-cleanup-");
17 dispatch_io_t channel
;
19 dispatch_fd_t fd
= open(path
, O_CREAT
| O_WRONLY
, 0666);
21 channel
= dispatch_io_create(DISPATCH_IO_STREAM
, fd
, queue
, ^(int error
) {
23 dispatch_semaphore_signal(sem
);
25 if (! channel
) abort();
27 dispatch_io_close(channel
, 0);
28 dispatch_semaphore_wait(sem
, DISPATCH_TIME_FOREVER
);
31 channel
= dispatch_io_create_with_path(DISPATCH_IO_STREAM
, path
, O_CREAT
| O_WRONLY
, 0666, queue
, ^(int error
) {
33 dispatch_semaphore_signal(sem
);
35 if (! channel
) abort();
37 dispatch_io_close(channel
, 0);
38 dispatch_semaphore_wait(sem
, DISPATCH_TIME_FOREVER
);
41 dispatch_io_t other_channel
= dispatch_io_create_with_path(DISPATCH_IO_STREAM
, path
, O_CREAT
| O_WRONLY
, 0666, queue
, ^(int error
) { });
42 channel
= dispatch_io_create_with_io(DISPATCH_IO_STREAM
, other_channel
, queue
, ^(int error
) {
44 dispatch_semaphore_signal(sem
);
46 if (! channel
) abort();
48 dispatch_io_close(channel
, 0);
49 dispatch_io_close(other_channel
, 0);
50 dispatch_semaphore_wait(sem
, DISPATCH_TIME_FOREVER
);
52 fprintf(stderr
, "Done.\n");
56 // CHECK: Hello world.