brintos

brintos / llvm-project-archived public Read only

0
0
Text · 605 B · 01c4490 Raw
34 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 fds[2];7int X;8 9void *Thread1(void *x) {10  X = 42;11  write(fds[1], "a", 1);12  return NULL;13}14 15void *Thread2(void *x) {16  char buf;17  while (read(fds[0], &buf, 1) != 1) {18  }19  X = 43;20  return NULL;21}22 23int main() {24  pipe(fds);25  pthread_t t[2];26  pthread_create(&t[0], NULL, Thread1, NULL);27  pthread_create(&t[1], NULL, Thread2, NULL);28  pthread_join(t[0], NULL);29  pthread_join(t[1], NULL);30  fprintf(stderr, "OK\n");31}32 33// CHECK-NOT: WARNING: ThreadSanitizer: data race34