From 2f6ad63a58d638920c60b5d7fe7d4a6a63066398 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Tue, 26 Sep 2017 11:01:29 +0300 Subject: [PATCH] Fix removal of dead threads in a child process GC_threads table may contain several elements with the same pthread id, so GC_remove_all_threads_but_me should remove all elements except for the first found element matching the id of the current thread. * pthread_support.c [CAN_HANDLE_FORK] (GC_remove_all_threads_but_me): Do not assign me if it is already non-null; add comment. * win32_threads.c [CAN_HANDLE_FORK] (GC_remove_all_threads_but_me): Likewise. * win32_threads.c [CAN_HANDLE_FORK] (GC_remove_all_threads_but_me): Remove GC_ASSERT(me==NULL). --- pthread_support.c | 3 ++- win32_threads.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pthread_support.c b/pthread_support.c index 379848c..2694ec8 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -754,7 +754,8 @@ STATIC void GC_remove_all_threads_but_me(void) me = 0; for (p = GC_threads[hv]; 0 != p; p = next) { next = p -> next; - if (THREAD_EQUAL(p -> id, self)) { + if (THREAD_EQUAL(p -> id, self) + && me == NULL) { /* ignore dead threads with the same id */ me = p; p -> next = 0; # ifdef GC_DARWIN_THREADS diff --git a/win32_threads.c b/win32_threads.c index 24f16db..18acb57 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -1031,8 +1031,8 @@ GC_API void * GC_CALL GC_call_with_gc_active(GC_fn_type fn, for (hv = 0; hv < THREAD_TABLE_SZ; ++hv) { for (p = GC_threads[hv]; 0 != p; p = next) { next = p -> tm.next; - if (THREAD_EQUAL(p -> pthread_id, pthread_id)) { - GC_ASSERT(me == NULL); + if (THREAD_EQUAL(p -> pthread_id, pthread_id) + && me == NULL) { /* ignore dead threads with the same id */ me = p; p -> tm.next = 0; } else { -- 2.7.4