| 1 | // RUN: %clang_tsan %s -o %t |
| 2 | // RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer' |
| 3 | |
| 4 | #include <dispatch/dispatch.h> |
| 5 | |
| 6 | #include <stdio.h> |
| 7 | |
| 8 | long global; |
| 9 | |
| 10 | int main() { |
| 11 | fprintf(stderr, format: "Hello world." ); |
| 12 | |
| 13 | global = 42; |
| 14 | |
| 15 | dispatch_semaphore_t sem = dispatch_semaphore_create(0); |
| 16 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ |
| 17 | |
| 18 | global = 43; |
| 19 | dispatch_semaphore_signal(sem); |
| 20 | }); |
| 21 | |
| 22 | dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER); |
| 23 | global = 44; |
| 24 | |
| 25 | fprintf(stderr, format: "Done." ); |
| 26 | return 0; |
| 27 | } |
| 28 | |
| 29 | // CHECK: Hello world. |
| 30 | // CHECK: Done. |
| 31 | |