1 /** Cause a race inside code protected by a reader lock.
5 /* Needed for older glibc's (2.3 and older, at least) who don't
6 otherwise "know" about pthread_rwlock_anything or about
7 PTHREAD_MUTEX_RECURSIVE (amongst things). */
17 static pthread_rwlock_t s_rwlock;
20 static void sleep_ms(const int ms)
22 struct timespec delay = { ms / 1000, (ms % 1000) * 1000 * 1000 };
26 static void* thread_func(void* arg)
28 pthread_rwlock_rdlock(&s_rwlock);
30 pthread_rwlock_unlock(&s_rwlock);
35 int main(int argc, char** argv)
42 VALGRIND_DO_CLIENT_REQUEST_EXPR(0, VG_USERREQ__DRD_TRACE_ADDR,
46 pthread_rwlock_init(&s_rwlock, 0);
47 pthread_create(&thread1, 0, thread_func, 0);
48 pthread_create(&thread2, 0, thread_func, 0);
49 pthread_join(thread1, 0);
50 pthread_join(thread2, 0);
51 pthread_rwlock_destroy(&s_rwlock);
53 fprintf(stderr, "Result: %d\n", s_racy);