Home | History | Annotate | Download | only in Darwin
      1 // RUN: %clang_tsan %s -o %t -framework Foundation
      2 // RUN: %deflake %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   barrier_init(&barrier, 2);
     14 
     15   global = 42;
     16   dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
     17     global = 43;
     18     barrier_wait(&barrier);
     19   });
     20 
     21   dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
     22     barrier_wait(&barrier);
     23     global = 44;
     24 
     25     dispatch_sync(dispatch_get_main_queue(), ^{
     26       CFRunLoopStop(CFRunLoopGetCurrent());
     27     });
     28   });
     29 
     30   CFRunLoopRun();
     31   NSLog(@"Done.");
     32 }
     33 
     34 // CHECK: Hello world.
     35 // CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
     36 // CHECK: WARNING: ThreadSanitizer: data race
     37 // CHECK: Location is global 'global' at [[ADDR]] (global_race.cc.exe+0x{{[0-9,a-f]+}})
     38 // CHECK: Done.
     39