Bugzilla bug #32779: PR_Interrupt should increment the cv's
authorwtc%netscape.com
Wed, 22 Mar 2000 18:47:54 +0000
changeset 1251 4217aaa004ca214ef5ab720714164a1e8a2a9c93
parent 1250 4097818b71614a380d59f1f229e9bad24e6950f0
child 1252 faa32a2b1ad26a79eb659be5f7dde46b2ea28f00
push idunknown
push userunknown
push dateunknown
bugs32779
Bugzilla bug #32779: PR_Interrupt should increment the cv's pending_notify count before broadcasting on the cv to prevent the interrupted thread from destroying the cv before pthread_cond_broadcast returns.
pr/src/pthreads/ptthread.c
--- a/pr/src/pthreads/ptthread.c
+++ b/pr/src/pthreads/ptthread.c
@@ -649,18 +649,22 @@ PR_IMPLEMENT(PRStatus) PR_Interrupt(PRTh
     PR_ASSERT(NULL != thred);
     if (NULL == thred) return PR_FAILURE;
 
     thred->state |= PT_THREAD_ABORTED;
 
     cv = thred->waiting;
     if ((NULL != cv) && !thred->interrupt_blocked)
     {
-        PRIntn rv = pthread_cond_broadcast(&cv->cv);
+        PRIntn rv;
+        (void)PR_AtomicIncrement(&cv->notify_pending);
+        rv = pthread_cond_broadcast(&cv->cv);
         PR_ASSERT(0 == rv);
+        if (0 > PR_AtomicDecrement(&cv->notify_pending))
+            PR_DestroyCondVar(cv);
     }
     return PR_SUCCESS;
 }  /* PR_Interrupt */
 
 PR_IMPLEMENT(void) PR_ClearInterrupt()
 {
     PRThread *me = PR_CurrentThread();
     me->state &= ~PT_THREAD_ABORTED;