Bugzilla bug #21666: _pt_root should wait on pt_book.cv before decrementing NSPRPUB_RELEASE_4_0_BRANCH
authorwtc%netscape.com
Tue, 25 Jan 2000 01:53:21 +0000
branchNSPRPUB_RELEASE_4_0_BRANCH
changeset 1074 076063ccaa48edad522318d144b61264dfb39fbb
parent 1073 4df14efc4d25a8ef26a6788db3cce9c914fdf8d4
child 1077 b2383c7689c88841d54fe52bcf095dc1abbb15aa
push idunknown
push userunknown
push dateunknown
bugs21666
Bugzilla bug #21666: _pt_root should wait on pt_book.cv before decrementing active thread count, so that PR_Cleanup can correctly determine that pt_book.cv is no longer in use. (NSPRPUB_RELEASE_4_0_BRANCH)
pr/src/pthreads/ptthread.c
--- a/pr/src/pthreads/ptthread.c
+++ b/pr/src/pthreads/ptthread.c
@@ -153,36 +153,36 @@ static void *_pt_root(void *arg)
     thred->next = NULL;
     pt_book.last = thred;
     PR_Unlock(pt_book.ml);
 
     thred->startFunc(thred->arg);  /* make visible to the client */
 
     /* unhook the thread from the runtime */
     PR_Lock(pt_book.ml);
-    if (thred->state & PT_THREAD_SYSTEM)
-        pt_book.system -= 1;
-    else if (--pt_book.user == pt_book.this_many)
-        PR_NotifyAllCondVar(pt_book.cv);
-    thred->prev->next = thred->next;
-    if (NULL == thred->next)
-        pt_book.last = thred->prev;
-    else
-        thred->next->prev = thred->prev;
-
     /*
      * At this moment, PR_CreateThread() may not have set thred->id yet.
      * It is safe for a detached thread to free thred only after
      * PR_CreateThread() has set thred->id.
      */
     if (detached)
     {
         while (!thred->okToDelete)
             PR_WaitCondVar(pt_book.cv, PR_INTERVAL_NO_TIMEOUT);
     }
+
+    if (thred->state & PT_THREAD_SYSTEM)
+        pt_book.system -= 1;
+    else if (--pt_book.user == pt_book.this_many)
+        PR_NotifyAllCondVar(pt_book.cv);
+    thred->prev->next = thred->next;
+    if (NULL == thred->next)
+        pt_book.last = thred->prev;
+    else
+        thred->next->prev = thred->prev;
     PR_Unlock(pt_book.ml);
 
     /*
     * Here we set the pthread's backpointer to the PRThread to NULL.
     * Otherwise the desctructor would get called eagerly as the thread
     * returns to the pthread runtime. The joining thread would them be
     * the proud possessor of a dangling reference. However, this is the
     * last chance to delete the object if the thread is detached, so