1// Check that we don't crash when dispatch_main calls pthread_exit which
2// quits the main thread.
3
4// RUN: %clang_tsan %s -o %t
5// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
6
7#include <dispatch/dispatch.h>
8
9#include <stdio.h>
10#include <stdlib.h>
11
12int main() {
13 fprintf(stderr,format: "Hello world");
14
15 dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL);
16
17 dispatch_async(q, ^{
18 fprintf(stderr,format: "1");
19 });
20
21 dispatch_async(q, ^{
22 fprintf(stderr,format: "2");
23 });
24
25 dispatch_async(q, ^{
26 fprintf(stderr,format: "3");
27
28 dispatch_async(dispatch_get_main_queue(), ^{
29 fprintf(stderr,format: "Done.");
30 sleep(1);
31 exit(status: 0);
32 });
33 });
34
35 dispatch_main();
36}
37
38// CHECK: Hello world
39// CHECK: 123
40// CHECK: Done.
41

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