From: Ivan Maidanski Date: Tue, 26 Sep 2017 08:44:44 +0000 (+0300) Subject: Fix pthread_join when thread is registered in thread key destructor X-Git-Tag: v7.4.6~18 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=874f2d11dce397722e36f91588d869d178ce9e7e;p=gc Fix pthread_join when thread is registered in thread key destructor * pthread_support.c (WRAP_FUNC(pthread_join)): Remove assertion that thread is finished; call GC_delete_gc_thread only if thread is finished; add comment. * win32_threads.c [GC_PTHREADS] (GC_pthread_join): Call GC_delete_gc_thread_no_free and GC_INTERNAL_FREE only if thread is finished. --- diff --git a/pthread_support.c b/pthread_support.c index 2dc9da2b..d9369e48 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -1431,9 +1431,11 @@ GC_API int WRAP_FUNC(pthread_join)(pthread_t thread, void **retval) # endif if (result == 0) { LOCK(); - /* Here the pthread thread id may have been recycled. */ - GC_ASSERT((t -> flags & FINISHED) != 0); - GC_delete_gc_thread(t); + /* Here the pthread thread id may have been recycled. */ + /* Delete the thread from GC_threads (unless it has been */ + /* registered again from the client thread key destructor). */ + if ((t -> flags & FINISHED) != 0) + GC_delete_gc_thread(t); UNLOCK(); } return result; diff --git a/win32_threads.c b/win32_threads.c index 5b757f34..f8f9954e 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -2501,8 +2501,10 @@ GC_INNER void GC_thr_init(void) # endif LOCK(); + if ((t -> flags & FINISHED) != 0) { GC_delete_gc_thread_no_free(t); GC_INTERNAL_FREE(t); + } UNLOCK(); }