Home | History | Annotate | Download | only in Darwin
      1 // RUN: %clang_tsan %s -o %t -framework Foundation
      2 // RUN: %run %t 2>&1
      3 
      4 #import <Foundation/Foundation.h>
      5 
      6 #import "../test.h"
      7 
      8 long global;
      9 
     10 int main() {
     11   NSLog(@"Hello world.");
     12   NSLog(@"addr=%p\n", &global);
     13 
     14   dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
     15   global = 42;
     16 
     17   dispatch_group_t g = dispatch_group_create();
     18   dispatch_group_async(g, q, ^{
     19     global = 43;
     20   });
     21   dispatch_group_wait(g, DISPATCH_TIME_FOREVER);
     22 
     23   global = 44;
     24 
     25   dispatch_group_enter(g);
     26   dispatch_async(q, ^{
     27     global = 45;
     28     dispatch_group_leave(g);
     29   });
     30   dispatch_group_wait(g, DISPATCH_TIME_FOREVER);
     31 
     32   global = 46;
     33 
     34   dispatch_group_enter(g);
     35   dispatch_async(q, ^{
     36     global = 47;
     37     dispatch_group_leave(g);
     38   });
     39   dispatch_group_notify(g, q, ^{
     40     global = 48;
     41 
     42     dispatch_sync(dispatch_get_main_queue(), ^{
     43       CFRunLoopStop(CFRunLoopGetCurrent());
     44     });
     45   });
     46 
     47   CFRunLoopRun();
     48   NSLog(@"Done.");
     49 }
     50 
     51 // CHECK: Hello world.
     52 // CHECK: Done.
     53 // CHECK-NOT: WARNING: ThreadSanitizer
     54