diff options
author | Roland McGrath <roland@gnu.org> | 2004-09-22 21:21:10 +0000 |
---|---|---|
committer | Roland McGrath <roland@gnu.org> | 2004-09-22 21:21:10 +0000 |
commit | b5707b44d25d7af61b0338c2a2206c036eaf7337 (patch) | |
tree | d8b9e865cbc78d64835a63959370865a2a043223 /nptl/pthread_cond_destroy.c | |
parent | 4ff389feb39f2eb649530b843d478c80c27ab4cf (diff) | |
download | glibc-b5707b44d25d7af61b0338c2a2206c036eaf7337.tar glibc-b5707b44d25d7af61b0338c2a2206c036eaf7337.tar.gz glibc-b5707b44d25d7af61b0338c2a2206c036eaf7337.tar.bz2 glibc-b5707b44d25d7af61b0338c2a2206c036eaf7337.zip |
Changes and additions migrated from cvs.devel.redhat.com:/cvs/devel/glibc to fedora-branch
Diffstat (limited to 'nptl/pthread_cond_destroy.c')
-rw-r--r-- | nptl/pthread_cond_destroy.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/nptl/pthread_cond_destroy.c b/nptl/pthread_cond_destroy.c index 0208d18ce4..3e4ec8d0e4 100644 --- a/nptl/pthread_cond_destroy.c +++ b/nptl/pthread_cond_destroy.c @@ -44,15 +44,35 @@ __pthread_cond_destroy (cond) broadcasted, but still are using the pthread_cond_t structure, pthread_cond_destroy needs to wait for them. */ unsigned int nwaiters = cond->__data.__nwaiters; - while (nwaiters >= (1 << COND_CLOCK_BITS)) + + if (nwaiters >= (1 << COND_CLOCK_BITS)) { - lll_mutex_unlock (cond->__data.__lock); + /* Wake everybody on the associated mutex in case there are + threads that have been requeued to it. + Without this, pthread_cond_destroy could block potentially + for a long time or forever, as it would depend on other + thread's using the mutex. + When all threads waiting on the mutex are woken up, pthread_cond_wait + only waits for threads to acquire and release the internal + condvar lock. */ + if (cond->__data.__mutex != NULL + && cond->__data.__mutex != (void *) ~0l) + { + pthread_mutex_t *mut = (pthread_mutex_t *) cond->__data.__mutex; + lll_futex_wake (&mut->__data.__lock, INT_MAX); + } + + do + { + lll_mutex_unlock (cond->__data.__lock); - lll_futex_wait (&cond->__data.__nwaiters, nwaiters); + lll_futex_wait (&cond->__data.__nwaiters, nwaiters); - lll_mutex_lock (cond->__data.__lock); + lll_mutex_lock (cond->__data.__lock); - nwaiters = cond->__data.__nwaiters; + nwaiters = cond->__data.__nwaiters; + } + while (nwaiters >= (1 << COND_CLOCK_BITS)); } return 0; |