]>
git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/tsan/mop1.c
1 // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
4 // We want to establish the following sequence of accesses to X:
5 // - main thread writes X
6 // - thread2 reads X, this read happens-before the write in main thread
7 // - thread1 reads X, this read is concurrent with the write in main thread
8 // Write in main thread and read in thread1 should be detected as a race.
9 // Previously tsan replaced write by main thread with read by thread1,
10 // as the result the race was not detected.
12 volatile long X
, Y
, Z
;
14 void *Thread1(void *x
) {
15 barrier_wait(&barrier
);
16 barrier_wait(&barrier
);
21 void *Thread2(void *x
) {
23 barrier_wait(&barrier
);
28 barrier_init(&barrier
, 2);
30 pthread_create(&t
[0], 0, Thread1
, 0);
32 barrier_wait(&barrier
);
33 pthread_create(&t
[1], 0, Thread2
, 0);
34 pthread_join(t
[0], 0);
35 pthread_join(t
[1], 0);
39 // CHECK: WARNING: ThreadSanitizer: data race