1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
4 pthread_rwlock_t rwlock
;
7 void *Thread1(void *p
) {
9 pthread_rwlock_rdlock(&rwlock
);
10 barrier_wait(&barrier
);
11 // Write under reader lock.
13 pthread_rwlock_unlock(&rwlock
);
17 int main(int argc
, char *argv
[]) {
18 barrier_init(&barrier
, 2);
19 pthread_rwlock_init(&rwlock
, NULL
);
20 pthread_rwlock_rdlock(&rwlock
);
22 pthread_create(&t
, 0, Thread1
, 0);
23 volatile int x
= GLOB
;
25 pthread_rwlock_unlock(&rwlock
);
26 barrier_wait(&barrier
);
28 pthread_rwlock_destroy(&rwlock
);
32 // CHECK: WARNING: ThreadSanitizer: data race
33 // CHECK: Write of size 4 at {{.*}} by thread T1{{.*}}:
34 // CHECK: #0 Thread1(void*) {{.*}}write_in_reader_lock.cpp:12
35 // CHECK: Previous read of size 4 at {{.*}} by main thread{{.*}}:
36 // CHECK: #0 main {{.*}}write_in_reader_lock.cpp:23