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 #include <sys/types.h>
6 #include <sys/socket.h>
7
8 int fds[2];
9 int X;
10
Thread1(void * x)11 void *Thread1(void *x) {
12 X = 42;
13 write(fds[1], "a", 1);
14 close(fds[1]);
15 return NULL;
16 }
17
Thread2(void * x)18 void *Thread2(void *x) {
19 char buf;
20 while (read(fds[0], &buf, 1) != 1) {
21 }
22 X = 43;
23 close(fds[0]);
24 return NULL;
25 }
26
main()27 int main() {
28 socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
29 pthread_t t[2];
30 pthread_create(&t[0], NULL, Thread1, NULL);
31 pthread_create(&t[1], NULL, Thread2, NULL);
32 pthread_join(t[0], NULL);
33 pthread_join(t[1], NULL);
34 fprintf(stderr, "OK\n");
35 }
36
37 // CHECK-NOT: WARNING: ThreadSanitizer: data race
38