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
This commit is contained in:
Mike Makonnen 2003-05-29 20:46:53 +00:00
parent 981f4968f0
commit b3cdf7ae2e
3 changed files with 21 additions and 12 deletions

View File

@ -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. */

View File

@ -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);
}
/*

View File

@ -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;
}