[ASan/Win] Add a comment about DCL-using-static vs threads
[blocksruntime.git] / test / tsan / fork_multithreaded3.cc
bloba651b3c18b4e7af4befa1bf2c7ccd2969373e33f
1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <errno.h>
5 #include <pthread.h>
6 #include <unistd.h>
7 #include <sys/types.h>
8 #include <sys/wait.h>
10 static void *racer(void *p) {
11 *(int*)p = 42;
12 return 0;
15 int main() {
16 switch (fork()) {
17 default: // parent
18 while (wait(0) < 0) {}
19 break;
20 case 0: // child
22 int x = 0;
23 pthread_t th1, th2;
24 pthread_create(&th1, 0, racer, &x);
25 pthread_create(&th2, 0, racer, &x);
26 pthread_join(th1, 0);
27 pthread_join(th2, 0);
28 exit(0);
29 break;
31 case -1: // error
32 fprintf(stderr, "failed to fork (%d)\n", errno);
33 exit(1);
35 fprintf(stderr, "OK\n");
38 // CHECK: ThreadSanitizer: data race
39 // CHECK: OK