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
6int pipes[2];
7
8void *Thread(void *x) {
9  // wait for shutown signal
10  while (read(pipes[0], &x, 1) != 1) {
11  }
12  close(pipes[0]);
13  close(pipes[1]);
14  return 0;
15}
16
17int main() {
18  if (pipe(pipes))
19    return 1;
20  pthread_t t;
21  pthread_create(&t, 0, Thread, 0);
22  // send shutdown signal
23  while (write(pipes[1], &t, 1) != 1) {
24  }
25  pthread_join(t, 0);
26  printf("OK\n");
27}
28
29// CHECK-NOT: WARNING: ThreadSanitizer: data race
30// CHECK: OK
31