1// Check that we don't crash when dispatch_main calls pthread_exit which 2// quits the main thread. 3 4// RUN: %clang_tsan %s -o %t -framework Foundation 5// RUN: %env_tsan_opts=ignore_interceptors_accesses=1 %run %t 2>&1 | FileCheck %s 6 7#import <Foundation/Foundation.h> 8 9int main() { 10 fprintf(stderr,"Hello world"); 11 12 dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL); 13 14 dispatch_async(q, ^{ 15 fprintf(stderr,"1"); 16 }); 17 18 dispatch_async(q, ^{ 19 fprintf(stderr,"2"); 20 }); 21 22 dispatch_async(q, ^{ 23 fprintf(stderr,"3"); 24 25 dispatch_async(dispatch_get_main_queue(), ^{ 26 fprintf(stderr,"Done."); 27 sleep(1); 28 exit(0); 29 }); 30 }); 31 32 dispatch_main(); 33} 34 35// CHECK: Hello world 36// CHECK: Done. 37// CHECK-NOT: WARNING: ThreadSanitizer 38// CHECK-NOT: CHECK failed 39