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.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'winsup/cygwin/thread.h') diff --git a/winsup/cygwin/thread.h b/winsup/cygwin/thread.h index 05638d9c6..121d35af9 100644 --- a/winsup/cygwin/thread.h +++ b/winsup/cygwin/thread.h @@ -587,6 +587,18 @@ private: void remove_reader (struct RWLOCK_READER *rd); struct RWLOCK_READER *lookup_reader (pthread_t thread); + void release () + { + if (waiting_writers) + { + if (!readers) + cond_writers.unblock (false); + } + else if (waiting_readers) + cond_readers.unblock (true); + } + + static void rdlock_cleanup (void *arg); static void wrlock_cleanup (void *arg); -- cgit v1.2.3