1 | // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s |
2 | #include "test.h" |
3 | #include <sys/types.h> |
4 | #include <sys/stat.h> |
5 | #include <fcntl.h> |
6 | |
7 | void *Thread1(void *x) { |
8 | int f = open(file: "/dev/random" , O_RDONLY); |
9 | close(fd: f); |
10 | barrier_wait(barrier: &barrier); |
11 | return NULL; |
12 | } |
13 | |
14 | void *Thread2(void *x) { |
15 | barrier_wait(barrier: &barrier); |
16 | int f = open(file: "/dev/random" , O_RDONLY); |
17 | close(fd: f); |
18 | return NULL; |
19 | } |
20 | |
21 | int main() { |
22 | barrier_init(barrier: &barrier, count: 2); |
23 | pthread_t t[2]; |
24 | pthread_create(newthread: &t[0], NULL, start_routine: Thread1, NULL); |
25 | pthread_create(newthread: &t[1], NULL, start_routine: Thread2, NULL); |
26 | pthread_join(th: t[0], NULL); |
27 | pthread_join(th: t[1], NULL); |
28 | fprintf(stderr, format: "OK\n" ); |
29 | } |
30 | |
31 | // CHECK-NOT: WARNING: ThreadSanitizer: data race |
32 | |
33 | |
34 | |