From: Ivan Maidanski Date: Thu, 14 Dec 2017 07:24:34 +0000 (+0300) Subject: Workaround TSan false positive in remove_all_threads_but_me X-Git-Tag: v8.0.0~448 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a239976a7fe8e98f8e6d9afc2bb812cee720a445;p=gc Workaround TSan false positive in remove_all_threads_but_me * pthread_support.c [CAN_HANDLE_FORK] (store_to_threads_table): New static function (defined with GC_ATTR_NO_SANITIZE_THREAD attribute if CAN_CALL_ATFORK); add comment. * pthread_support.c [CAN_CALL_ATFORK] (GC_remove_all_threads_but_me): Call store_to_threads_table instead of GC_threads[hv]=me. --- diff --git a/pthread_support.c b/pthread_support.c index 9dc7ba56..ae262fde 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -737,6 +737,18 @@ GC_API void GC_CALL GC_register_altstack(void *stack, GC_word stack_size, } #ifdef CAN_HANDLE_FORK + + /* Prevent TSan false positive about the race during items removal */ + /* from GC_threads. (The race cannot happen since only one thread */ + /* survives in the child.) */ +# ifdef CAN_CALL_ATFORK + GC_ATTR_NO_SANITIZE_THREAD +# endif + static void store_to_threads_table(int hv, GC_thread me) + { + GC_threads[hv] = me; + } + /* Remove all entries from the GC_threads table, except the */ /* one for the current thread. We need to do this in the child */ /* process after a fork(), since only the current thread */ @@ -792,7 +804,7 @@ STATIC void GC_remove_all_threads_but_me(void) if (p != &first_thread) GC_INTERNAL_FREE(p); } } - GC_threads[hv] = me; + store_to_threads_table(hv, me); } } #endif /* CAN_HANDLE_FORK */