LinuxThreads read write lock patch.
Kaz Kylheku
kaz@ashi.footprints.net
Tue Jan 11 23:50:00 GMT 2000
I've been doing some more testing which has covered recursive read locks in the
face of waiting writers. Looks good. I made one minor change after reading
the damn spec more closely. The pthread_rwlock_tryrdlock function is required
to test for waiting writers and return EBUSY. This is even if the calling
thread has a read lock---whereas pthread_rwlock_rdlock must be recursive.
Go figure. Also, pthread_rwlock_rdlock is not required to give precedence
to waiting writers (it is unspecified what happens if writers are waiting)
whereas tryrdlock is required. Go figure again. There is brain-damage at every
corner in the Single Unix Spec.
diff -u -r1.1.1.1.2.1 -r1.1.1.1.2.2
--- rwlock.c 2000/01/12 03:03:58 1.1.1.1.2.1
+++ rwlock.c 2000/01/12 07:34:51 1.1.1.1.2.2
@@ -276,7 +276,13 @@
__pthread_lock (&rwlock->__rw_lock, self);
- if (rwlock_can_rdlock(rwlock, have_lock_already))
+ /* 0 is passed to here instead of have_lock_already.
+ This is to meet Single Unix Spec requirements:
+ if writers are waiting, pthread_rwlock_tryrdlock
+ does not acquire a read lock, even if the caller has
+ one or more read locks already. */
+
+ if (rwlock_can_rdlock(rwlock, 0))
{
++rwlock->__rw_readers;
retval = 0;
More information about the Libc-alpha
mailing list