| 1 | // RUN: %clang_tsan %s -o %t -framework Foundation |
| 2 | // RUN: %deflake %run %t 2>&1 | FileCheck %s |
| 3 | |
| 4 | #import <Foundation/Foundation.h> |
| 5 | |
| 6 | #import "../test.h" |
| 7 | |
| 8 | long global; |
| 9 | |
| 10 | int main() { |
| 11 | fprintf(stderr, format: "Hello world.\n" ); |
| 12 | print_address("addr=" , 1, &global); |
| 13 | barrier_init(barrier: &barrier, count: 2); |
| 14 | |
| 15 | global = 42; |
| 16 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ |
| 17 | global = 43; |
| 18 | barrier_wait(barrier: &barrier); |
| 19 | }); |
| 20 | |
| 21 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ |
| 22 | barrier_wait(barrier: &barrier); |
| 23 | global = 44; |
| 24 | |
| 25 | dispatch_sync(dispatch_get_main_queue(), ^{ |
| 26 | CFRunLoopStop(CFRunLoopGetCurrent()); |
| 27 | }); |
| 28 | }); |
| 29 | |
| 30 | CFRunLoopRun(); |
| 31 | fprintf(stderr, format: "Done.\n" ); |
| 32 | } |
| 33 | |
| 34 | // CHECK: Hello world. |
| 35 | // CHECK: WARNING: ThreadSanitizer: data race |
| 36 | // CHECK: Write of size 8 |
| 37 | // CHECK: Previous write of size 8 |
| 38 | // CHECK: Location is global |
| 39 | // CHECK: Thread {{.*}} is a GCD worker thread |
| 40 | // CHECK-NOT: failed to restore the stack |
| 41 | // CHECK: Thread {{.*}} is a GCD worker thread |
| 42 | // CHECK-NOT: failed to restore the stack |
| 43 | // CHECK: Done. |
| 44 | |