llvm-project
26 строк · 512.0 Байт
1// RUN: %clang_tsan -O1 %s -o %t && %env_tsan_opts=halt_on_error=1 %deflake %run %t | FileCheck %s
2#include "test.h"
3
4int X;
5
6void *Thread(void *x) {
7barrier_wait(&barrier);
8X = 42;
9return 0;
10}
11
12int main() {
13barrier_init(&barrier, 2);
14fprintf(stderr, "BEFORE\n");
15pthread_t t;
16pthread_create(&t, 0, Thread, 0);
17X = 43;
18barrier_wait(&barrier);
19pthread_join(t, 0);
20fprintf(stderr, "AFTER\n");
21return 0;
22}
23
24// CHECK: BEFORE
25// CHECK: WARNING: ThreadSanitizer: data race
26// CHECK-NOT: AFTER
27
28