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 <assert.h>
8
9int main() {
10 fprintf(stderr, format: "start\n");
11 dispatch_semaphore_t done = dispatch_semaphore_create(0);
12
13 dispatch_queue_t background_q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
14 dispatch_queue_t serial_q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL);
15 assert(background_q != serial_q);
16
17 dispatch_async(background_q, ^{
18 __block long block_var = 0;
19
20 dispatch_sync(serial_q, ^{
21 block_var = 42;
22 });
23
24 fprintf(stderr, "block_var = %ld\n", block_var);
25
26 dispatch_semaphore_signal(done);
27 });
28
29 dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
30 fprintf(stderr, format: "done\n");
31}
32
33// CHECK: start
34// CHECK: block_var = 42
35// CHECK: done
36

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