brintos

brintos / llvm-project-archived public Read only

0
0
Text · 573 B · 382ae5f Raw
31 lines · cpp
1// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s2#include <pthread.h>3#include <stdio.h>4#include <unistd.h>5 6int pipes[2];7 8void *Thread(void *x) {9  // wait for shutown signal10  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 signal23  while (write(pipes[1], &t, 1) != 1) {24  }25  pthread_join(t, 0);26  fprintf(stderr, "OK\n");27}28 29// CHECK-NOT: WARNING: ThreadSanitizer: data race30// CHECK: OK31