summaryrefslogtreecommitdiffstats
path: root/lib/libthr
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libthr')
-rw-r--r--lib/libthr/thread/thr_exit.c24
-rw-r--r--lib/libthr/thread/thr_gc.c7
-rw-r--r--lib/libthr/thread/thr_join.c2
3 files changed, 21 insertions, 12 deletions
diff --git a/lib/libthr/thread/thr_exit.c b/lib/libthr/thread/thr_exit.c
index dd510b1..bea7874 100644
--- a/lib/libthr/thread/thr_exit.c
+++ b/lib/libthr/thread/thr_exit.c
@@ -173,28 +173,30 @@ retry:
PTHREAD_SET_STATE(curthread, PS_DEAD);
_thread_critical_exit(curthread);
- /*
- * Signal the garbage collector thread that there is something
- * to clean up.
- */
- if (pthread_cond_signal(&_gc_cond) != 0)
- PANIC("Cannot signal gc cond");
-
/* If we're the last thread, call it quits */
if (TAILQ_EMPTY(&_thread_list))
exitNow = 1;
THREAD_LIST_UNLOCK;
- DEAD_LIST_UNLOCK;
+
+ /*
+ * Signal the garbage collector thread that there is something
+ * to clean up. But don't allow it to free the memory until after
+ * it is retired by holding on to the dead list lock.
+ */
+ if (pthread_cond_signal(&_gc_cond) != 0)
+ PANIC("Cannot signal gc cond");
if (exitNow)
exit(0);
+ DEAD_LIST_UNLOCK;
+
/*
- * Retire the architecture specific id so that it can be used for
- * new threads.
+ * This function will not return unless we are the last
+ * thread, which we can't be because we've already checked
+ * for that.
*/
- _retire_thread(curthread->arch_id);
_thr_exit();
/* This point should not be reached. */
diff --git a/lib/libthr/thread/thr_gc.c b/lib/libthr/thread/thr_gc.c
index 9e26314..e2aa753 100644
--- a/lib/libthr/thread/thr_gc.c
+++ b/lib/libthr/thread/thr_gc.c
@@ -142,6 +142,13 @@ _thread_gc(pthread_addr_t arg)
pthread_cln = pthread;
_SPINUNLOCK(&pthread->lock);
+
+ /*
+ * Retire the architecture specific id so it may be
+ * used for new threads.
+ */
+ _retire_thread(pthread_cln->arch_id);
+
}
/*
diff --git a/lib/libthr/thread/thr_join.c b/lib/libthr/thread/thr_join.c
index 88a71f2..2a5433a 100644
--- a/lib/libthr/thread/thr_join.c
+++ b/lib/libthr/thread/thr_join.c
@@ -160,9 +160,9 @@ _pthread_join(pthread_t pthread, void **thread_return)
/* Make the thread collectable by the garbage collector. */
pthread->attr.flags |= PTHREAD_DETACHED;
_SPINUNLOCK(&pthread->lock);
+ THREAD_LIST_UNLOCK;
if (pthread_cond_signal(&_gc_cond) != 0)
PANIC("Cannot signal gc cond");
- THREAD_LIST_UNLOCK;
DEAD_LIST_UNLOCK;
}
OpenPOWER on IntegriCloud