From dc3a8b52c0f870cb23ddea843431bacca03fc629 Mon Sep 17 00:00:00 2001 From: John Birrell Date: Wed, 30 Sep 1998 06:36:56 +0000 Subject: Move the cleanup code that frees memory allocated for a dead thread from the thread kernel into a garbage collector thread which is started when the fisrt thread is created (other than the initial thread). This removes the window of opportunity where a context switch will cause a thread that has locked the malloc spinlock, to enter the thread kernel, find there is a dead thread and try to free memory, therefore trying to lock the malloc spinlock against itself. The garbage collector thread acts just like any other thread, so instead of having a spinlock to control accesses to the dead thread list, it uses a mutex and a condition variable so that it can happily wait to be signalled when a thread exists. --- lib/libpthread/thread/thr_init.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/libpthread/thread/thr_init.c') diff --git a/lib/libpthread/thread/thr_init.c b/lib/libpthread/thread/thr_init.c index 69b0fef563ae..50f3bef8973a 100644 --- a/lib/libpthread/thread/thr_init.c +++ b/lib/libpthread/thread/thr_init.c @@ -251,6 +251,11 @@ _thread_init(void) __set_dynamic_handler_allocator( dynamic_allocator_handler_fn ); #endif /* GCC_2_8_MADE_THREAD_AWARE */ + /* Initialise the garbage collector mutex and condition variable. */ + if (pthread_mutex_init(&_gc_mutex,NULL) != 0 || + pthread_cond_init(&_gc_cond,NULL) != 0) + PANIC("Failed to initialise garbage collector mutex or condvar"); + return; } -- cgit v1.2.3