diff options
Diffstat (limited to 'test/tsan/Darwin/gcd-groups-norace.mm')
-rw-r--r-- | test/tsan/Darwin/gcd-groups-norace.mm | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/tsan/Darwin/gcd-groups-norace.mm b/test/tsan/Darwin/gcd-groups-norace.mm new file mode 100644 index 000000000000..fb4d804ed8c7 --- /dev/null +++ b/test/tsan/Darwin/gcd-groups-norace.mm @@ -0,0 +1,53 @@ +// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %run %t 2>&1 + +#import <Foundation/Foundation.h> + +#import "../test.h" + +long global; + +int main() { + NSLog(@"Hello world."); + NSLog(@"addr=%p\n", &global); + + dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); + global = 42; + + dispatch_group_t g = dispatch_group_create(); + dispatch_group_async(g, q, ^{ + global = 43; + }); + dispatch_group_wait(g, DISPATCH_TIME_FOREVER); + + global = 44; + + dispatch_group_enter(g); + dispatch_async(q, ^{ + global = 45; + dispatch_group_leave(g); + }); + dispatch_group_wait(g, DISPATCH_TIME_FOREVER); + + global = 46; + + dispatch_group_enter(g); + dispatch_async(q, ^{ + global = 47; + dispatch_group_leave(g); + }); + dispatch_group_notify(g, q, ^{ + global = 48; + + dispatch_sync(dispatch_get_main_queue(), ^{ + CFRunLoopStop(CFRunLoopGetCurrent()); + }); + }); + + CFRunLoopRun(); + NSLog(@"Done."); +} + +// CHECK: Hello world. +// CHECK: Done. +// CHECK-NOT: WARNING: ThreadSanitizer |