1// RUN: %clang_tsan %s -o %t -framework Foundation 2// RUN: %env_tsan_opts=ignore_interceptors_accesses=1 %deflake %run %t 2>&1 | FileCheck %s 3 4#import <Foundation/Foundation.h> 5 6#import "../test.h" 7 8long global; 9 10int main() { 11 fprintf(stderr, "Hello world.\n"); 12 print_address("addr=", 1, &global); 13 barrier_init(&barrier, 2); 14 15 dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT); 16 dispatch_queue_t bgq = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); 17 18 dispatch_barrier_sync(q, ^{ 19 global = 42; 20 }); 21 22 dispatch_async(bgq, ^{ 23 dispatch_sync(q, ^{ 24 global = 43; 25 barrier_wait(&barrier); 26 }); 27 }); 28 29 dispatch_async(bgq, ^{ 30 dispatch_sync(q, ^{ 31 barrier_wait(&barrier); 32 global = 44; 33 34 dispatch_sync(dispatch_get_main_queue(), ^{ 35 CFRunLoopStop(CFRunLoopGetCurrent()); 36 }); 37 }); 38 }); 39 40 CFRunLoopRun(); 41 fprintf(stderr, "Done.\n"); 42} 43 44// CHECK: Hello world. 45// CHECK: addr=[[ADDR:0x[0-9,a-f]+]] 46// CHECK: WARNING: ThreadSanitizer: data race 47// CHECK: Location is global 'global' {{(of size 8 )?}}at [[ADDR]] (gcd-barrier-race.mm.tmp+0x{{[0-9,a-f]+}}) 48// CHECK: Done. 49