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 6long global; 7 8void handler(void *arg) { 9 fprintf(stderr, "global = %ld\n", global); 10 11 dispatch_sync(dispatch_get_main_queue(), ^{ 12 CFRunLoopStop(CFRunLoopGetCurrent()); 13 }); 14} 15 16int main(int argc, const char *argv[]) { 17 dispatch_queue_t queue = 18 dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT); 19 20 dispatch_source_t source = 21 dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); 22 23 dispatch_source_set_timer(source, dispatch_walltime(NULL, 0), 1e9, 5); 24 25 global = 42; 26 27 dispatch_source_set_cancel_handler_f(source, &handler); 28 29 dispatch_resume(source); 30 dispatch_cancel(source); 31 32 CFRunLoopRun(); 33 34 return 0; 35} 36 37// CHECK: global = 42 38// CHECK-NOT: WARNING: ThreadSanitizer 39