From ffb576fbf2440548e717bf7f37b3aafa48ee2fbc Mon Sep 17 00:00:00 2001 From: Thomas Pfaff Date: Tue, 15 Apr 2003 20:14:12 +0000 Subject: Fix a race in pthread_rwlock caused by simultanoues unlock and cancelation. * thread.h (pthread_rwlock::release): New method. * thread.cc (pthread_rwlock::unlock): Use release to signal waiting threads. (pthread_rwlock::rdlock_cleanup): Signal waiting threads after a cancelation. (pthread_rwlock::wrlock_cleanup): Ditto. --- winsup/cygwin/thread.cc | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'winsup/cygwin/thread.cc') diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index 0eadd03c5..5f0917ad6 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -1210,13 +1210,7 @@ pthread_rwlock::unlock () delete reader; } - if (waiting_writers) - { - if (!readers) - cond_writers.unblock (false); - } - else if (waiting_readers) - cond_readers.unblock (true); + release (); DONE: mtx.unlock (); @@ -1263,6 +1257,7 @@ pthread_rwlock::rdlock_cleanup (void *arg) pthread_rwlock *rwlock = (pthread_rwlock *) arg; --(rwlock->waiting_readers); + rwlock->release (); rwlock->mtx.unlock (); } @@ -1272,6 +1267,7 @@ pthread_rwlock::wrlock_cleanup (void *arg) pthread_rwlock *rwlock = (pthread_rwlock *) arg; --(rwlock->waiting_writers); + rwlock->release (); rwlock->mtx.unlock (); } -- cgit v1.2.3