#define _GNU_SOURCE 1
-#include <stdio.h>
#include <pthread.h>
+#include <stdio.h>
+#include <unistd.h>
#include "../drd_clientreq.h"
static pthread_rwlock_t s_rwlock;
static int s_racy;
-static void* thread(void* arg)
+static void sleep_ms(const int ms)
+{
+ struct timespec delay = { ms / 1000, (ms % 1000) * 1000 * 1000 };
+ nanosleep(&delay, 0);
+}
+
+static void* thread_func(void* arg)
{
pthread_rwlock_rdlock(&s_rwlock);
s_racy++;
pthread_rwlock_unlock(&s_rwlock);
+ sleep_ms(100);
return 0;
}
#endif
pthread_rwlock_init(&s_rwlock, 0);
- pthread_create(&thread1, 0, thread, 0);
- pthread_create(&thread2, 0, thread, 0);
+ pthread_create(&thread1, 0, thread_func, 0);
+ pthread_create(&thread2, 0, thread_func, 0);
pthread_join(thread1, 0);
pthread_join(thread2, 0);
pthread_rwlock_destroy(&s_rwlock);
-Thread 2:
-Conflicting load by thread 2/3 at 0x........ size 4
- at 0x........: thread (rwlock_race.c:?)
+Thread 3:
+Conflicting load by thread 3/3 at 0x........ size 4
+ at 0x........: thread_func (rwlock_race.c:?)
by 0x........: vg_thread_wrapper (drd_pthread_intercepts.c:?)
by 0x........: (within libpthread-?.?.so)
by 0x........: clone (in /...libc...)
Location 0x........ is 0 bytes inside local var "s_racy"
-declared at rwlock_race.c:17, in frame #? of thread 2
-Other segment start (thread 0/2)
- (thread finished, call stack no longer available)
-Other segment end (thread 0/2)
- (thread finished, call stack no longer available)
+declared at rwlock_race.c:18, in frame #? of thread 3
+Other segment start (thread 2/2)
+ at 0x........: pthread_rwlock_rdlock* (drd_pthread_intercepts.c:?)
+ by 0x........: thread_func (rwlock_race.c:?)
+ by 0x........: vg_thread_wrapper (drd_pthread_intercepts.c:?)
+ by 0x........: (within libpthread-?.?.so)
+ by 0x........: clone (in /...libc...)
+Other segment end (thread 2/2)
+ at 0x........: pthread_rwlock_unlock* (drd_pthread_intercepts.c:?)
+ by 0x........: thread_func (rwlock_race.c:?)
+ by 0x........: vg_thread_wrapper (drd_pthread_intercepts.c:?)
+ by 0x........: (within libpthread-?.?.so)
+ by 0x........: clone (in /...libc...)
-Conflicting store by thread 2/3 at 0x........ size 4
- at 0x........: thread (rwlock_race.c:?)
+Conflicting store by thread 3/3 at 0x........ size 4
+ at 0x........: thread_func (rwlock_race.c:?)
by 0x........: vg_thread_wrapper (drd_pthread_intercepts.c:?)
by 0x........: (within libpthread-?.?.so)
by 0x........: clone (in /...libc...)
Location 0x........ is 0 bytes inside local var "s_racy"
-declared at rwlock_race.c:17, in frame #? of thread 2
-Other segment start (thread 0/2)
- (thread finished, call stack no longer available)
-Other segment end (thread 0/2)
- (thread finished, call stack no longer available)
+declared at rwlock_race.c:18, in frame #? of thread 3
+Other segment start (thread 2/2)
+ at 0x........: pthread_rwlock_rdlock* (drd_pthread_intercepts.c:?)
+ by 0x........: thread_func (rwlock_race.c:?)
+ by 0x........: vg_thread_wrapper (drd_pthread_intercepts.c:?)
+ by 0x........: (within libpthread-?.?.so)
+ by 0x........: clone (in /...libc...)
+Other segment end (thread 2/2)
+ at 0x........: pthread_rwlock_unlock* (drd_pthread_intercepts.c:?)
+ by 0x........: thread_func (rwlock_race.c:?)
+ by 0x........: vg_thread_wrapper (drd_pthread_intercepts.c:?)
+ by 0x........: (within libpthread-?.?.so)
+ by 0x........: clone (in /...libc...)
Result: 2
ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)