| 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s |
| 2 | #include "syscall.h" |
| 3 | #include "../test.h" |
| 4 | #include <errno.h> |
| 5 | #include <sys/types.h> |
| 6 | #include <sys/wait.h> |
| 7 | |
| 8 | int pipefd[2]; |
| 9 | unsigned long long buf[2]; |
| 10 | |
| 11 | static void *thr(void *p) { |
| 12 | barrier_wait(barrier: &barrier); |
| 13 | mywrite(fd: pipefd[1], buf, count: sizeof(buf)); |
| 14 | return 0; |
| 15 | } |
| 16 | |
| 17 | int main() { |
| 18 | barrier_init(barrier: &barrier, count: 2); |
| 19 | if (mypipe(pipefd)) |
| 20 | exit(status: (perror(s: "pipe" ), 1)); |
| 21 | mywrite(fd: pipefd[1], buf, count: sizeof(buf)); |
| 22 | pthread_t th; |
| 23 | pthread_create(newthread: &th, attr: 0, start_routine: thr, arg: 0); |
| 24 | myread(fd: pipefd[0], buf, count: sizeof(buf)); |
| 25 | barrier_wait(barrier: &barrier); |
| 26 | pthread_join(th: th, thread_return: 0); |
| 27 | fprintf(stderr, format: "DONE\n" ); |
| 28 | } |
| 29 | |
| 30 | // CHECK: WARNING: ThreadSanitizer: data race |
| 31 | // CHECK: Read of size 8 |
| 32 | // CHECK: #0 mywrite |
| 33 | // CHECK: #1 thr |
| 34 | // CHECK: Previous write of size 8 |
| 35 | // CHECK: #0 myread |
| 36 | // CHECK: #1 main |
| 37 | // CHECK: DONE |
| 38 | |