| 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 | #include <string.h> |
| 8 | |
| 9 | long global = 42; |
| 10 | |
| 11 | int main(int argc, const char *argv[]) { |
| 12 | fprintf(stderr, format: "Hello world.\n" ); |
| 13 | |
| 14 | dispatch_queue_t q = dispatch_queue_create("my.queue" , DISPATCH_QUEUE_SERIAL); |
| 15 | dispatch_semaphore_t sem = dispatch_semaphore_create(0); |
| 16 | |
| 17 | const char *buffer = "buffer" ; |
| 18 | size_t size = strlen(s: buffer); |
| 19 | |
| 20 | dispatch_data_t data = dispatch_data_create(buffer, size, q, ^{ |
| 21 | fprintf(stderr, "Data destructor.\n" ); |
| 22 | global++; |
| 23 | |
| 24 | dispatch_semaphore_signal(sem); |
| 25 | }); |
| 26 | dispatch_release(data); |
| 27 | |
| 28 | dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER); |
| 29 | |
| 30 | data = dispatch_data_create(buffer, size, q, DISPATCH_DATA_DESTRUCTOR_DEFAULT); |
| 31 | dispatch_release(data); |
| 32 | |
| 33 | fprintf(stderr, format: "Done.\n" ); |
| 34 | } |
| 35 | |
| 36 | // CHECK: Hello world. |
| 37 | // CHECK: Data destructor. |
| 38 | // CHECK: Done. |
| 39 | |