brintos

brintos / llvm-project-archived public Read only

0
0
Text · 731 B · b94893b Raw
38 lines · cpp
1// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s2#include "test.h"3 4int fds[2];5 6void *Thread1(void *x) {7  write(fds[1], "a", 1);8  barrier_wait(&barrier);9  return NULL;10}11 12void *Thread2(void *x) {13  barrier_wait(&barrier);14  close(fds[0]);15  close(fds[1]);16  return NULL;17}18 19int main() {20  barrier_init(&barrier, 2);21  pipe(fds);22  pthread_t t[2];23  pthread_create(&t[0], NULL, Thread1, NULL);24  pthread_create(&t[1], NULL, Thread2, NULL);25  pthread_join(t[0], NULL);26  pthread_join(t[1], NULL);27}28 29// CHECK: WARNING: ThreadSanitizer: data race30// CHECK:   Write of size 831// CHECK:     #0 close32// CHECK:     #1 Thread233// CHECK:   Previous read of size 834// CHECK:     #0 write35// CHECK:     #1 Thread136 37 38