From: Ivan Maidanski Date: Sun, 26 Feb 2012 15:36:11 +0000 (+0400) Subject: Fix GC_remove_all_threads_but_me for fork-unfriendly TLS implementations X-Git-Tag: gc7_3alpha2~87 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8bf44e780f4ed98835c049d5269886bb62179c15;p=gc Fix GC_remove_all_threads_but_me for fork-unfriendly TLS implementations * pthread_support.c (GC_remove_all_threads_but_me): Refine comment for stop_info.mach_thread update. * pthread_support.c (GC_remove_all_threads_but_me): Call GC_setspecific (if THREAD_LOCAL_ALLOC) to re-assign thread-local pointer to 'tlfs' (identified by GC_thread_key) of the current thread (except for USE_CUSTOM_SPECIFIC). --- diff --git a/pthread_support.c b/pthread_support.c index e1bfc945..3e628588 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -664,8 +664,18 @@ STATIC void GC_remove_all_threads_but_me(void) me = p; p -> next = 0; # ifdef GC_DARWIN_THREADS - /* Update thread Id after fork. */ + /* Update thread Id after fork (it is ok to call */ + /* GC_destroy_thread_local and GC_free_internal */ + /* before update). */ me -> stop_info.mach_thread = mach_thread_self(); +# endif +# if defined(THREAD_LOCAL_ALLOC) && !defined(USE_CUSTOM_SPECIFIC) + /* Some TLS implementations might be not fork-friendly, so */ + /* we re-assign thread-local pointer to 'tlfs' for safety */ + /* instead of the assertion check (again, it is ok to call */ + /* GC_destroy_thread_local and GC_free_internal before). */ + if (GC_setspecific(GC_thread_key, &me->tlfs) != 0) + ABORT("GC_setspecific failed (in child)"); # endif } else { # ifdef THREAD_LOCAL_ALLOC