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 | |
7 | void *Thread(void *arg) { |
8 | char buf; |
9 | read(fd: (long)arg, buf: &buf, nbytes: 1); |
10 | barrier_wait(barrier: &barrier); |
11 | return NULL; |
12 | } |
13 | |
14 | int main() { |
15 | barrier_init(barrier: &barrier, count: 2); |
16 | int fd = open(file: "/dev/random", O_RDONLY); |
17 | pthread_t t; |
18 | pthread_create(newthread: &t, NULL, start_routine: Thread, arg: (void *)(long)fd); |
19 | barrier_wait(barrier: &barrier); |
20 | close(fd: fd); |
21 | pthread_join(th: t, NULL); |
22 | fprintf(stderr, format: "DONE\n"); |
23 | } |
24 | |
25 | // CHECK: WARNING: ThreadSanitizer: data race |
26 | // CHECK: DONE |
27 |