diff --git a/tests/test-lock.c b/tests/test-lock.c
index 095511e..336daeb 100644
--- a/tests/test-lock.c
+++ b/tests/test-lock.c
@@ -17,6 +17,7 @@
/* Written by Bruno Haible
, 2005. */
#include
+#include
#if USE_POSIX_THREADS || USE_SOLARIS_THREADS || USE_PTH_THREADS || USE_WINDOWS_THREADS
@@ -41,10 +42,10 @@
/* Which tests to perform.
Uncomment some of these, to verify that all tests crash if no locking
is enabled. */
-#define DO_TEST_LOCK 1
+#define DO_TEST_LOCK 0
#define DO_TEST_RWLOCK 1
-#define DO_TEST_RECURSIVE_LOCK 1
-#define DO_TEST_ONCE 1
+#define DO_TEST_RECURSIVE_LOCK 0
+#define DO_TEST_ONCE 0
/* Whether to help the scheduler through explicit yield().
Uncomment this to see if the operating system has a fair scheduler. */
@@ -58,10 +59,10 @@
#define USE_VOLATILE 0
/* Whether to print debugging messages. */
-#define ENABLE_DEBUGGING 0
+#define ENABLE_DEBUGGING 1
/* Number of simultaneous threads. */
-#define THREAD_COUNT 10
+#define THREAD_COUNT 3
/* Number of operations performed in each thread.
This is quite high, because with a smaller count, say 5000, we often get
@@ -312,11 +313,20 @@ static struct atomic_int rwlock_checker_done;
static void *
rwlock_checker_thread (void *arg)
{
+ int tid = *((int *)arg);
while (get_atomic_int_value (&rwlock_checker_done) == 0)
{
dbgprintf ("Checker %p before check rdlock\n", gl_thread_self_pointer ());
gl_rwlock_rdlock (my_rwlock);
check_accounts ();
+
+ /* Wait about (THREAD_COUNT - 1) seconds in critical section, so (if
+ * writers are not prefered) at least one reader has ackquired rdonly
+ * lock and writers starve. */
+ while (time(NULL) % THREAD_COUNT != tid)
+ usleep(100000);
+ usleep(800000);
+
gl_rwlock_unlock (my_rwlock);
dbgprintf ("Checker %p after check unlock\n", gl_thread_self_pointer ());
@@ -342,7 +352,7 @@ test_rwlock (void)
/* Spawn the threads. */
for (i = 0; i < THREAD_COUNT; i++)
- checkerthreads[i] = gl_thread_create (rwlock_checker_thread, NULL);
+ checkerthreads[i] = gl_thread_create (rwlock_checker_thread, &i);
for (i = 0; i < THREAD_COUNT; i++)
threads[i] = gl_thread_create (rwlock_mutator_thread, NULL);