From b85fec2ded3f005b877e25b63215c0d09d4a9f7f Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 1 Oct 2011 09:11:35 -0400 Subject: [PATCH] fix failure-to-wake in rwlock unlock a reader unlocking the lock need only wake one waiter (necessarily a writer, but a writer unlocking the lock must wake all waiters (necessarily readers). if it only wakes one, the remainder can remain blocked indefinitely, or at least until the first reader unlocks (in which case the whole lock becomes serialized and behaves as a mutex rather than a read lock). --- src/thread/pthread_rwlock_unlock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thread/pthread_rwlock_unlock.c b/src/thread/pthread_rwlock_unlock.c index 5edca634..a6d20854 100644 --- a/src/thread/pthread_rwlock_unlock.c +++ b/src/thread/pthread_rwlock_unlock.c @@ -12,7 +12,7 @@ int pthread_rwlock_unlock(pthread_rwlock_t *rw) } while (a_cas(&rw->_rw_lock, val, new) != val); if (!new && (waiters || val<0)) - __wake(&rw->_rw_lock, 1, 0); + __wake(&rw->_rw_lock, cnt, 0); return 0; } -- 2.25.1