From 1862d961a9b18acbf30d9391e091d91de9c0f16d Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Fri, 2 Jul 2021 09:52:56 +1200 Subject: [PATCH] Ignore dead threads in `coroutine_join`. --- coroutine/pthread/Context.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/coroutine/pthread/Context.c b/coroutine/pthread/Context.c index bbf2d4c1a9..38774cda0b 100644 --- a/coroutine/pthread/Context.c +++ b/coroutine/pthread/Context.c @@ -237,9 +237,13 @@ struct coroutine_context * coroutine_transfer(struct coroutine_context * current static void coroutine_join(struct coroutine_context * context) { if (DEBUG) fprintf(stderr, "coroutine_join:pthread_cancel\n"); - check("coroutine_join:pthread_cancel", - pthread_cancel(context->id) - ); + int result = pthread_cancel(context->id); + if (result == -1 && errno == ESRCH) { + // The thread may be dead due to fork, so it cannot be joined and this doesn't represent a real error: + return; + } + + check("coroutine_join:pthread_cancel", result); if (DEBUG) fprintf(stderr, "coroutine_join:pthread_join\n"); check("coroutine_join:pthread_join",