blob: cb8fb4bf5eca17e71783a62afc8101156d6d2c94 [file] [log] [blame]
Kuba Brecka440d0862015-11-24 13:36:06 +00001// RUN: %clang_tsan %s -o %t -framework Foundation
Kuba Mraceke4c1dd22017-01-24 21:37:50 +00002// RUN: %deflake %run %t 2>&1 | FileCheck %s
Kuba Brecka440d0862015-11-24 13:36:06 +00003
4#import <Foundation/Foundation.h>
5
6#import "../test.h"
7
8long global;
9
10int main() {
11 NSLog(@"Hello world.");
Kuba Breckaaafb41a2016-04-07 11:31:02 +000012 print_address("addr=", 1, &global);
Kuba Brecka440d0862015-11-24 13:36:06 +000013 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
Kuba Breckaaafb41a2016-04-07 11:31:02 +000037// CHECK: Location is global 'global' {{(of size 8 )?}}at [[ADDR]] (gcd-async-race.mm.tmp+0x{{[0-9,a-f]+}})
Kuba Brecka440d0862015-11-24 13:36:06 +000038// CHECK: Done.