diff options
author | mtm <mtm@FreeBSD.org> | 2003-05-29 20:46:53 +0000 |
---|---|---|
committer | mtm <mtm@FreeBSD.org> | 2003-05-29 20:46:53 +0000 |
commit | e0fdf7a90db60211ee59359697c41dab2d566785 (patch) | |
tree | 24627382282fb3a2ee03fe4390d9fac487628e88 | |
parent | 9863dd8503db3fadb6ae84c6eee25d7ee94a2a5a (diff) | |
download | FreeBSD-src-e0fdf7a90db60211ee59359697c41dab2d566785.zip FreeBSD-src-e0fdf7a90db60211ee59359697c41dab2d566785.tar.gz |
Don't hold the active thread list lock when signaling the gc thread.
The dead list thread is sufficient for synchronization.
Retire the arch_id (ldt array slot) in the gc thread instead of the
doing it in the thread itself.
Approved by: re/jhb
-rw-r--r-- | lib/libthr/thread/thr_exit.c | 24 | ||||
-rw-r--r-- | lib/libthr/thread/thr_gc.c | 7 | ||||
-rw-r--r-- | lib/libthr/thread/thr_join.c | 2 |
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; } |