| 1 |
/* { dg-shouldfail "tsan" } */ |
| 2 |
/* { dg-additional-options "-ldl" } */ |
| 3 |
|
| 4 |
#include <pthread.h> |
| 5 |
#include "tsan_barrier.h" |
| 6 |
|
| 7 |
static pthread_barrier_t barrier; |
| 8 |
pthread_rwlock_t rwlock; |
| 9 |
int GLOB; |
| 10 |
|
| 11 |
void *Thread1(void *p) { |
| 12 |
(void)p; |
| 13 |
pthread_rwlock_rdlock(&rwlock); |
| 14 |
// Write under reader lock. |
| 15 |
barrier_wait(&barrier); |
| 16 |
GLOB++; |
| 17 |
pthread_rwlock_unlock(&rwlock); |
| 18 |
return 0; |
| 19 |
} |
| 20 |
|
| 21 |
int main(int argc, char *argv[]) { |
| 22 |
barrier_init(&barrier, 2); |
| 23 |
pthread_rwlock_init(&rwlock, NULL); |
| 24 |
pthread_rwlock_rdlock(&rwlock); |
| 25 |
pthread_t t; |
| 26 |
pthread_create(&t, 0, Thread1, 0); |
| 27 |
volatile int x = GLOB; |
| 28 |
(void)x; |
| 29 |
pthread_rwlock_unlock(&rwlock); |
| 30 |
barrier_wait(&barrier); |
| 31 |
pthread_join(t, 0); |
| 32 |
pthread_rwlock_destroy(&rwlock); |
| 33 |
return 0; |
| 34 |
} |
| 35 |
|
| 36 |
/* { dg-output "WARNING: ThreadSanitizer: data race.*(\n|\r\n|\r)" } */ |
| 37 |
/* { dg-output " Write of size 4 at 0x\[0-9a-f\]+ by thread T1.*:(\n|\r\n|\r).*" } */ |
| 38 |
/* { dg-output " #0 Thread1.*\(write_in_reader_lock.c|\\?{2}\):\[0-9\]+ .*" } */ |
| 39 |
/* { dg-output " Previous read of size 4 at.* by main thread.*:(\n|\r\n|\r).*" } */ |
| 40 |
/* { dg-output " #0 main.*\(write_in_reader_lock.c|\\?{2}\):\[0-9\]+.*" } */ |