1 // RUN: %clang_tsan %s -o %t -framework Foundation
2 // RUN: %run %t 2>&1 | FileCheck %s
4 #import <Foundation/Foundation.h>
6 dispatch_queue_t queue;
8 dispatch_semaphore_t sem;
13 int main(int argc, const char *argv[]) {
14 fprintf(stderr, "Hello world.\n");
16 queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
17 sem = dispatch_semaphore_create(0);
18 NSString *ns_path = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"temp-gcd-io.%d", getpid()]];
19 path = ns_path.fileSystemRepresentation;
20 NSData *ns_data = [NSMutableData dataWithLength:1000];
21 data = dispatch_data_create(ns_data.bytes, ns_data.length, NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
23 dispatch_io_t channel = dispatch_io_create_with_path(DISPATCH_IO_STREAM, path, O_CREAT | O_WRONLY, 0666, queue, ^(int error) { });
24 if (! channel) abort();
25 dispatch_io_set_high_water(channel, 1);
27 for (int i = 0; i < 1000; i++) {
28 dispatch_io_barrier(channel, ^{
33 dispatch_io_barrier(channel, ^{
36 dispatch_semaphore_signal(sem);
39 dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
40 dispatch_io_close(channel, 0);
42 fprintf(stderr, "Done.\n");
46 // CHECK: Hello world.
47 // CHECK-NOT: WARNING: ThreadSanitizer