31 lines · c
1// RUN: %clang_tsan %s -o %t2// RUN: %deflake %run %t 2>&1 | FileCheck %s3 4#include <dispatch/dispatch.h>5 6#include "../test.h"7 8long global;9 10int main(int argc, const char *argv[]) {11 barrier_init(&barrier, 2);12 fprintf(stderr, "start\n");13 14 // Warm up GCD (workaround for macOS Sierra where dispatch_apply might run single-threaded).15 dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ });16 17 dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);18 dispatch_apply(2, q, ^(size_t i) {19 global = i;20 barrier_wait(&barrier);21 });22 23 fprintf(stderr, "done\n");24 return 0;25}26 27// CHECK: start28// CHECK: WARNING: ThreadSanitizer: data race29// CHECK: Location is global 'global'30// CHECK: done31