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
8long my_global;
9long my_global2;
10dispatch_semaphore_t done;
11
12void callback(void *context) {
13 my_global2 = 42;
14
15 dispatch_semaphore_signal(done);
16}
17
18int main(int argc, const char *argv[]) {
19 fprintf(stderr, format: "start\n");
20 done = dispatch_semaphore_create(0);
21
22 dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
23
24 my_global = 10;
25 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_MSEC)), q, ^{
26 my_global = 42;
27
28 dispatch_semaphore_signal(done);
29 });
30
31 my_global2 = 10;
32 dispatch_after_f(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_MSEC)), q, NULL, &callback);
33
34 dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
35 dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
36 fprintf(stderr, format: "done\n");
37 return 0;
38}
39
40// CHECK: start
41// CHECK: done
42

source code of compiler-rt/test/tsan/libdispatch/after.c