[ASan/Win] Add a comment about DCL-using-static vs threads
[blocksruntime.git] / test / tsan / fd_stdout_race.cc
blob47f3c6f6c1abda53438f805058ee2dc617672796
1 // RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
2 #include <pthread.h>
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
9 int X;
11 void *Thread1(void *x) {
12 sleep(1);
13 int f = open("/dev/random", O_RDONLY);
14 char buf;
15 read(f, &buf, 1);
16 close(f);
17 X = 42;
18 return NULL;
21 void *Thread2(void *x) {
22 X = 43;
23 write(STDOUT_FILENO, "a", 1);
24 return NULL;
27 int main() {
28 pthread_t t[2];
29 pthread_create(&t[0], NULL, Thread1, NULL);
30 pthread_create(&t[1], NULL, Thread2, NULL);
31 pthread_join(t[0], NULL);
32 pthread_join(t[1], NULL);
35 // CHECK: WARNING: ThreadSanitizer: data race
36 // CHECK: Write of size 4
37 // CHECK: #0 Thread1
38 // CHECK: Previous write of size 4
39 // CHECK: #0 Thread2