llvm-project
26 строк · 573.0 Байт
1// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2#include "test.h"
3#include <fcntl.h>
4#include <sys/stat.h>
5#include <sys/types.h>
6
7void *Thread(void *arg) {
8char buf;
9read((long)arg, &buf, 1);
10barrier_wait(&barrier);
11return NULL;
12}
13
14int main() {
15barrier_init(&barrier, 2);
16int fd = open("/dev/random", O_RDONLY);
17pthread_t t;
18pthread_create(&t, NULL, Thread, (void *)(long)fd);
19barrier_wait(&barrier);
20close(fd);
21pthread_join(t, NULL);
22fprintf(stderr, "DONE\n");
23}
24
25// CHECK: WARNING: ThreadSanitizer: data race
26// CHECK: DONE
27