From a4721b4a21397db07a5381fefe44227424669bd0 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Wed, 12 Jul 2017 01:10:42 +0300 Subject: [PATCH] Fix deadlock in GC_suspend_thread when thread is finished (fix commits 62097c3, 59e2bcf) * pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD] (GC_suspend_thread): Do not call RAISE_SIGNAL() and sem_wait() if thread has FINISHED flag set; do not handle ESRCH error result of RAISE_SIGNAL(); add comment. --- pthread_stop_world.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pthread_stop_world.c b/pthread_stop_world.c index 9fe65aec..07a2309e 100644 --- a/pthread_stop_world.c +++ b/pthread_stop_world.c @@ -433,15 +433,15 @@ STATIC void GC_restart_handler(int sig) (void)GC_do_blocking(suspend_self_inner, t); return; } + if ((t -> flags & FINISHED) != 0) { + /* Terminated but not joined yet. */ + UNLOCK(); + return; + } /* TODO: Support GC_retry_signals */ switch (RAISE_SIGNAL(t, GC_sig_suspend)) { - case ESRCH: - /* Not really there anymore (terminated but not joined yet). */ - /* No need to wait but leave the suspension flag on. */ - GC_ASSERT((t -> flags & FINISHED) != 0); - UNLOCK(); - return; + /* ESRCH cannot happen as terminated threads are handled above. */ case 0: break; default: -- 2.40.0