From e564950fd61e9ada9a0c6a599457508b8429c81b Mon Sep 17 00:00:00 2001
From: rpj <rpj>
Date: Sun, 26 Jul 1998 11:33:21 +0000
Subject: Sun Jul 26 13:06:12 1998  Ross Johnson 
 <rpj@ixobrychus.canberra.edu.au>

	* exit.c (_pthread_exit): Move thread entry delete call from _pthread_vacuum()
	into here. Add more explanation of thread entry deletion.
---
 ChangeLog |  2 ++
 exit.c    | 32 +++++++++++++++++---------------
 2 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ca94e5b..2cb372e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,8 @@ Sun Jul 26 13:06:12 1998  Ross Johnson  <rpj@ixobrychus.canberra.edu.au>
 	* exit.c (_pthread_exit): New function. Called from pthread_exit()
 	and _pthread_start_call() to exit the thread. It allows an extra
 	argument which is the return code passed to _endthreadex().
+	(_pthread_exit): Move thread entry delete call from _pthread_vacuum()
+	into here. Add more explanation of thread entry deletion.
 
 	* create.c (_pthread_start_call): Change pthread_exit() call to
 	_pthread_exit() call.
diff --git a/exit.c b/exit.c
index 37b5595..3714aa2 100644
--- a/exit.c
+++ b/exit.c
@@ -28,21 +28,6 @@ _pthread_vacuum(void)
 
   _pthread_handler_pop_all(_PTHREAD_FORKCHILD_STACK,
 			   _PTHREAD_HANDLER_NOEXECUTE);
-
-  /* CRITICAL SECTION */
-  pthread_mutex_lock(&_pthread_table_mutex);
-
-  /* Remove the thread entry on exit only if pthread_detach()
-     was called and there are no waiting joins. */
-
-  if (us->detach == TRUE
-      && us->join_count == 0)
-    {
-      _pthread_delete_thread_entry(us);
-    }
-
-  pthread_mutex_lock(&_pthread_table_mutex);
-  /* END CRITICAL SECTION */
 }
 
 void
@@ -62,6 +47,23 @@ _pthread_exit(void * value, int return_code)
 
   _pthread_vacuum();
 
+  /* CRITICAL SECTION */
+  pthread_mutex_lock(&_pthread_table_mutex);
+
+  /* Remove the thread entry on exit only if pthread_detach() was
+     called AND there are no waiting joins. Otherwise the thread entry
+     will be deleted by the last waiting pthread_join() after this
+     thread has terminated. */
+
+  if (us->detach == TRUE
+      && us->join_count == 0)
+    {
+      _pthread_delete_thread_entry(us);
+    }
+
+  pthread_mutex_lock(&_pthread_table_mutex);
+  /* END CRITICAL SECTION */
+
   _endthreadex(return_code);
 }
 
-- 
cgit v1.2.3