llvm-project
32 строки · 687.0 Байт
1// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2#include "test.h"3
4int X = 0;5
6__attribute__((noinline)) void MySleep() {7sleep(1); // the sleep that must appear in the report8}
9
10void *Thread(void *p) {11barrier_wait(&barrier);12MySleep(); // Assume the main thread has done the write.13X = 42;14return 0;15}
16
17int main() {18barrier_init(&barrier, 2);19pthread_t t;20pthread_create(&t, 0, Thread, 0);21X = 43;22barrier_wait(&barrier);23pthread_join(t, 0);24return 0;25}
26
27// CHECK: WARNING: ThreadSanitizer: data race
28// ...
29// CHECK: As if synchronized via sleep:
30// CHECK-NEXT: #0 sleep
31// CHECK-NEXT: #1 MySleep
32// CHECK-NEXT: #2 Thread
33