From 76a0e25462fdd8cd691cdcfe8606babd6b86e07c Mon Sep 17 00:00:00 2001 From: Stas Boukarev Date: Fri, 8 Jan 2016 00:17:52 +0300 Subject: [PATCH] Don't try to join threads coming from foreign callbacks. detach_os_thread calls undo_init_new_thread, which schedules the thread for a postmortem, which involves pthread_join on some platforms. Remove schedule_thread_post_mortem from undo_init_new_thread and call it only from new_thread_trampoline. --- src/runtime/thread.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/runtime/thread.c b/src/runtime/thread.c index 74832dad1..1d86d4d52 100644 --- a/src/runtime/thread.c +++ b/src/runtime/thread.c @@ -305,9 +305,16 @@ perform_thread_post_mortem(struct thread_post_mortem *post_mortem) #ifdef CREATE_POST_MORTEM_THREAD pthread_detach(pthread_self()); #endif + int result; if (post_mortem) { - gc_assert(!pthread_join(post_mortem->os_thread, NULL)); - gc_assert(!pthread_attr_destroy(post_mortem->os_attr)); + if ((result = pthread_join(post_mortem->os_thread, NULL))) { + lose("Error calling pthread_join in perform_thread_post_mortem:\n%s", + strerror(result)); + } + if ((result = pthread_attr_destroy(post_mortem->os_attr))) { + lose("Error calling pthread_attr_destroy in perform_thread_post_mortem:\n%s", + strerror(result)); + } free(post_mortem->os_attr); os_invalidate(post_mortem->os_address, THREAD_STRUCT_SIZE); free(post_mortem); @@ -476,8 +483,6 @@ undo_init_new_thread(struct thread *th, init_thread_data *scribble) #else pthread_setspecific(specials, NULL); #endif - - schedule_thread_post_mortem(th); } /* this is the first thing that runs in the child (which is why the @@ -503,6 +508,8 @@ new_thread_trampoline(struct thread *th) result = funcall0(function); undo_init_new_thread(th, &scribble); + schedule_thread_post_mortem(th); + FSHOW((stderr,"/exiting thread %lu\n", thread_self())); return result; } -- 2.11.4.GIT