From 2efa60a37de1602f2c867010b1eddda92211c7ad Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 3 Jul 2013 22:00:43 -0600 Subject: [PATCH] unlink thread later unlink thread from global list later also remove some unnecessary destruction code --- src/thread.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/thread.c b/src/thread.c index 361968489c6..8a81a1021a6 100644 --- a/src/thread.c +++ b/src/thread.c @@ -645,17 +645,6 @@ run_thread (void *state) update_processes_for_thread_death (Fcurrent_thread ()); - /* Unlink this thread from the list of all threads. */ - for (iter = &all_threads; *iter != self; iter = &(*iter)->next_thread) - ; - *iter = (*iter)->next_thread; - - self->m_last_thing_searched = Qnil; - self->m_saved_last_thing_searched = Qnil; - self->name = Qnil; - self->function = Qnil; - self->error_symbol = Qnil; - self->error_data = Qnil; xfree (self->m_specpdl); self->m_specpdl = NULL; self->m_specpdl_ptr = NULL; @@ -664,6 +653,14 @@ run_thread (void *state) current_thread = NULL; sys_cond_broadcast (&self->thread_condvar); + /* Unlink this thread from the list of all threads. Note that we + have to do this very late, after broadcasting our death. + Otherwise the GC may decide to reap the thread_state object, + leading to crashes. */ + for (iter = &all_threads; *iter != self; iter = &(*iter)->next_thread) + ; + *iter = (*iter)->next_thread; + release_global_lock (); return NULL; -- 2.39.5