Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / fd_socketpair_norace.cpp
blobbee030dd3249a3876b797d79abacd0620d213683
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>
8 int fds[2];
9 int X;
11 void *Thread1(void *x) {
12 X = 42;
13 write(fds[1], "a", 1);
14 close(fds[1]);
15 return NULL;
18 void *Thread2(void *x) {
19 char buf;
20 while (read(fds[0], &buf, 1) != 1) {
22 X = 43;
23 close(fds[0]);
24 return NULL;
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");
37 // CHECK-NOT: WARNING: ThreadSanitizer: data race