1// RUN: %clang_tsan %s -o %t -framework Foundation 2// RUN: %env_tsan_opts=ignore_interceptors_accesses=1 %run %t 2>&1 | FileCheck %s 3 4#import <Foundation/Foundation.h> 5 6#import "../test.h" 7 8long global; 9 10int main() { 11 NSLog(@"Hello world."); 12 NSLog(@"addr=%p\n", &global); 13 14 dispatch_queue_t q1 = dispatch_queue_create("my.queue1", DISPATCH_QUEUE_CONCURRENT); 15 dispatch_queue_t q2 = dispatch_queue_create("my.queue2", DISPATCH_QUEUE_SERIAL); 16 17 global = 42; 18 for (int i = 0; i < 10; i++) { 19 dispatch_async(q1, ^{ 20 for (int i = 0; i < 100; i++) { 21 dispatch_sync(q2, ^{ 22 global++; 23 }); 24 } 25 }); 26 } 27 28 dispatch_barrier_async(q1, ^{ 29 dispatch_sync(dispatch_get_main_queue(), ^{ 30 CFRunLoopStop(CFRunLoopGetCurrent()); 31 }); 32 }); 33 34 CFRunLoopRun(); 35 NSLog(@"Done."); 36} 37 38// CHECK: Hello world. 39// CHECK: Done. 40// CHECK-NOT: WARNING: ThreadSanitizer 41