Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / write_in_reader_lock.cpp
blob56aa1abebb01552fd3da7143e20da1cd6c011927
1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2 #include "test.h"
4 pthread_rwlock_t rwlock;
5 int GLOB;
7 void *Thread1(void *p) {
8 (void)p;
9 pthread_rwlock_rdlock(&rwlock);
10 barrier_wait(&barrier);
11 // Write under reader lock.
12 GLOB++;
13 pthread_rwlock_unlock(&rwlock);
14 return 0;
17 int main(int argc, char *argv[]) {
18 barrier_init(&barrier, 2);
19 pthread_rwlock_init(&rwlock, NULL);
20 pthread_rwlock_rdlock(&rwlock);
21 pthread_t t;
22 pthread_create(&t, 0, Thread1, 0);
23 volatile int x = GLOB;
24 (void)x;
25 pthread_rwlock_unlock(&rwlock);
26 barrier_wait(&barrier);
27 pthread_join(t, 0);
28 pthread_rwlock_destroy(&rwlock);
29 return 0;
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