[Sanitizer] Add rudimentary support for wide-character strings to scanf/printf interc...
[blocksruntime.git] / test / tsan / fork_multithreaded.cc
blobcceb83ec2018833d68c5e33f35ddc9288f55a5e7
1 // RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s -check-prefix=CHECK-DIE
2 // RUN: %clangxx_tsan -O1 %s -o %t && TSAN_OPTIONS="die_after_fork=0" %t 2>&1 | FileCheck %s -check-prefix=CHECK-NODIE
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <errno.h>
6 #include <pthread.h>
7 #include <unistd.h>
8 #include <sys/types.h>
9 #include <sys/wait.h>
11 static void *sleeper(void *p) {
12 sleep(10);
13 return 0;
16 int main() {
17 pthread_t th;
18 pthread_create(&th, 0, sleeper, 0);
19 switch (fork()) {
20 default: // parent
21 while (wait(0) < 0) {}
22 break;
23 case 0: // child
25 pthread_t th2;
26 pthread_create(&th2, 0, sleeper, 0);
27 exit(0);
28 break;
30 case -1: // error
31 fprintf(stderr, "failed to fork (%d)\n", errno);
32 exit(1);
34 fprintf(stderr, "OK\n");
37 // CHECK-DIE: ThreadSanitizer: starting new threads after multi-threaded fork is not supported
38 // CHECK-DIE: OK
40 // CHECK-NODIE-NOT: ThreadSanitizer: starting new threads after multi-threaded fork is not supported
41 // CHECK-NODIE: OK