2019-04-12 02:14:13 +08:00
|
|
|
// RUN: %clang_tsan %s -o %t
|
2019-05-17 02:57:36 +08:00
|
|
|
// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
|
2016-04-07 19:38:53 +08:00
|
|
|
|
2019-04-12 02:14:13 +08:00
|
|
|
#include "dispatch/dispatch.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2016-04-07 19:38:53 +08:00
|
|
|
|
|
|
|
long global;
|
2019-04-12 02:14:13 +08:00
|
|
|
dispatch_semaphore_t done;
|
2016-04-07 19:38:53 +08:00
|
|
|
|
|
|
|
void handler(void *arg) {
|
|
|
|
fprintf(stderr, "global = %ld\n", global);
|
|
|
|
|
2019-04-12 02:14:13 +08:00
|
|
|
dispatch_semaphore_signal(done);
|
2016-04-07 19:38:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, const char *argv[]) {
|
2019-04-12 02:14:13 +08:00
|
|
|
done = dispatch_semaphore_create(0);
|
|
|
|
|
2016-04-07 19:38:53 +08:00
|
|
|
dispatch_queue_t queue =
|
|
|
|
dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
|
|
|
|
|
|
|
|
dispatch_source_t source =
|
|
|
|
dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
|
|
|
|
|
|
|
|
dispatch_source_set_timer(source, dispatch_walltime(NULL, 0), 1e9, 5);
|
|
|
|
|
|
|
|
global = 42;
|
|
|
|
|
|
|
|
dispatch_source_set_cancel_handler_f(source, &handler);
|
|
|
|
|
|
|
|
dispatch_resume(source);
|
|
|
|
dispatch_cancel(source);
|
|
|
|
|
2019-04-12 02:14:13 +08:00
|
|
|
dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
|
2016-04-07 19:38:53 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: global = 42
|