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