llvm-project
32 строки · 692.0 Байт
1// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2#include "test.h"3
4int fds[2];5
6void *Thread1(void *x) {7write(fds[1], "a", 1);8barrier_wait(&barrier);9return NULL;10}
11
12void *Thread2(void *x) {13barrier_wait(&barrier);14close(fds[0]);15close(fds[1]);16return NULL;17}
18
19int main() {20barrier_init(&barrier, 2);21pipe(fds);22pthread_t t[2];23pthread_create(&t[0], NULL, Thread1, NULL);24pthread_create(&t[1], NULL, Thread2, NULL);25pthread_join(t[0], NULL);26pthread_join(t[1], NULL);27}
28
29// CHECK: WARNING: ThreadSanitizer: data race
30// CHECK: Location is file descriptor {{[0-9]+}} created by main thread at:
31// CHECK: #0 pipe
32// CHECK: #1 main
33
34