brintos

brintos / llvm-project-archived public Read only

0
0
Text · 810 B · fcf8c21 Raw
42 lines · cpp
1// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s2#include "test.h"3#include <sys/types.h>4#include <sys/stat.h>5#include <fcntl.h>6 7int X;8 9void *Thread1(void *x) {10  barrier_wait(&barrier);11  int f = open("/dev/random", O_RDONLY);12  char buf;13  read(f, &buf, 1);14  close(f);15  X = 42;16  return NULL;17}18 19void *Thread2(void *x) {20  X = 43;21  write(STDOUT_FILENO, "a", 1);22  barrier_wait(&barrier);23  return NULL;24}25 26int main() {27  barrier_init(&barrier, 2);28  pthread_t t[2];29  pthread_create(&t[0], NULL, Thread1, NULL);30  pthread_create(&t[1], NULL, Thread2, NULL);31  pthread_join(t[0], NULL);32  pthread_join(t[1], NULL);33}34 35// CHECK: WARNING: ThreadSanitizer: data race36// CHECK:   Write of size 437// CHECK:     #0 Thread138// CHECK:   Previous write of size 439// CHECK:     #0 Thread240 41 42