diff options
Diffstat (limited to 'test/tsan/Darwin/gcd-groups-stress.mm')
-rw-r--r-- | test/tsan/Darwin/gcd-groups-stress.mm | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/tsan/Darwin/gcd-groups-stress.mm b/test/tsan/Darwin/gcd-groups-stress.mm new file mode 100644 index 000000000000..62a80085ed8d --- /dev/null +++ b/test/tsan/Darwin/gcd-groups-stress.mm @@ -0,0 +1,43 @@ +// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %run %t 2>&1 + +#import <Foundation/Foundation.h> + +void notify_callback(void *context) { + // Do nothing. +} + +int main() { + NSLog(@"Hello world."); + + dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); + + for (int i = 0; i < 300000; i++) { + dispatch_group_t g = dispatch_group_create(); + dispatch_group_enter(g); + dispatch_async(q, ^{ + dispatch_group_leave(g); + }); + dispatch_group_notify(g, q, ^{ + // Do nothing. + }); + dispatch_release(g); + } + + for (int i = 0; i < 300000; i++) { + dispatch_group_t g = dispatch_group_create(); + dispatch_group_enter(g); + dispatch_async(q, ^{ + dispatch_group_leave(g); + }); + dispatch_group_notify_f(g, q, nullptr, ¬ify_callback); + dispatch_release(g); + } + + NSLog(@"Done."); +} + +// CHECK: Hello world. +// CHECK: Done. +// CHECK-NOT: WARNING: ThreadSanitizer +// CHECK-NOT: CHECK failed |