]> git.proxmox.com Git - rustc.git/blame - src/compiler-rt/test/tsan/write_in_reader_lock.cc
New upstream version 1.19.0+dfsg3
[rustc.git] / src / compiler-rt / test / tsan / write_in_reader_lock.cc
CommitLineData
92a42be0
SL
1// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2#include "test.h"
1a4d82fc
JJ
3
4pthread_rwlock_t rwlock;
5int GLOB;
6
7void *Thread1(void *p) {
8 (void)p;
9 pthread_rwlock_rdlock(&rwlock);
92a42be0 10 barrier_wait(&barrier);
1a4d82fc 11 // Write under reader lock.
1a4d82fc
JJ
12 GLOB++;
13 pthread_rwlock_unlock(&rwlock);
14 return 0;
15}
16
17int main(int argc, char *argv[]) {
92a42be0 18 barrier_init(&barrier, 2);
1a4d82fc
JJ
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);
92a42be0 26 barrier_wait(&barrier);
1a4d82fc
JJ
27 pthread_join(t, 0);
28 pthread_rwlock_destroy(&rwlock);
29 return 0;
30}
31
32// CHECK: WARNING: ThreadSanitizer: data race
33// CHECK: Write of size 4 at {{.*}} by thread T1{{.*}}:
92a42be0 34// CHECK: #0 Thread1(void*) {{.*}}write_in_reader_lock.cc:12
1a4d82fc
JJ
35// CHECK: Previous read of size 4 at {{.*}} by main thread{{.*}}:
36// CHECK: #0 main {{.*}}write_in_reader_lock.cc:23