1 | // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s |
2 | #include <pthread.h> |
3 | #include <stdio.h> |
4 | #include <unistd.h> |
5 | |
6 | int fds[2]; |
7 | int X; |
8 | |
9 | void *Thread1(void *x) { |
10 | X = 42; |
11 | write(fd: fds[1], buf: "a" , n: 1); |
12 | return NULL; |
13 | } |
14 | |
15 | void *Thread2(void *x) { |
16 | char buf; |
17 | while (read(fd: fds[0], buf: &buf, nbytes: 1) != 1) { |
18 | } |
19 | X = 43; |
20 | return NULL; |
21 | } |
22 | |
23 | int main() { |
24 | pipe(pipedes: fds); |
25 | pthread_t t[2]; |
26 | pthread_create(newthread: &t[0], NULL, start_routine: Thread1, NULL); |
27 | pthread_create(newthread: &t[1], NULL, start_routine: Thread2, NULL); |
28 | pthread_join(th: t[0], NULL); |
29 | pthread_join(th: t[1], NULL); |
30 | fprintf(stderr, format: "OK\n" ); |
31 | } |
32 | |
33 | // CHECK-NOT: WARNING: ThreadSanitizer: data race |
34 | |