From 7f97528c5c3e657629eb407b45fc858436f0af80 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Wed, 13 Apr 2022 08:38:58 +0300 Subject: Workaround race defect FP regarding thread_blocked in do_blocking_locked (fix of commit b3af80d5f) * include/private/pthread_stop_world.h [GC_ENABLE_SUSPEND_THREAD && SIGNAL_BASED_STOP_WORLD] (GC_suspend_self_inner): Move to pthread_support.h. * include/private/pthread_support.h [GC_ENABLE_SUSPEND_THREAD && SIGNAL_BASED_STOP_WORLD] (GC_suspend_self_inner): Change return type from void* to void; remove GC_CALLBACK; change argument type from void* to GC_thread. * pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL && SIGNAL_BASED_STOP_WORLD] (GC_suspend_self_inner): Likewise. * include/private/pthread_support.h [GC_ENABLE_SUSPEND_THREAD && SIGNAL_BASED_STOP_WORLD] (GC_suspend_self_blocked): Add comment. * pthread_support.c (do_blocking_locked): Replace static function with do_blocking_enter() and do_blocking_leave() ones; add assertion that the GC lock is held; declare topOfStackUnset variable unconditionally. * pthread_support.c (GC_do_blocking_inner): Add GC_ATTR_UNUSED to context argument; declare topOfStackUnset local variable; do not use do_blocking_locked(). * pthread_support.c [GC_ENABLE_SUSPEND_THREAD && SIGNAL_BASED_STOP_WORLD] (GC_suspend_self_blocked): Likewise. * pthread_support.c (GC_do_blocking_inner): Call do_blocking_enter(), then unlock, then call d->fn(), then lock, then call GC_suspend_self_inner() w/o lock while suspended_ext, then call do_blocking_leave(). * pthread_support.c [GC_ENABLE_SUSPEND_THREAD && SIGNAL_BASED_STOP_WORLD] (GC_suspend_self_blocked): Add comment; declare and use "me" local variable; remove assert that GC is locked; call do_blocking_enter(), then call GC_suspend_self_inner() w/o lock while suspended_ext, then call do_blocking_leave(). --- pthread_stop_world.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'pthread_stop_world.c') diff --git a/pthread_stop_world.c b/pthread_stop_world.c index 281fb352..6e02502f 100644 --- a/pthread_stop_world.c +++ b/pthread_stop_world.c @@ -626,14 +626,11 @@ STATIC void GC_restart_handler(int sig) (void)select(0, 0, 0, 0, &tv); } - GC_INNER void *GC_CALLBACK GC_suspend_self_inner(void *thread_me) { - GC_thread me = (GC_thread)thread_me; - + GC_INNER void GC_suspend_self_inner(GC_thread me) { while (ao_load_acquire_async(&me->suspended_ext)) { /* TODO: Use sigsuspend() instead. */ GC_brief_async_signal_safe_sleep(); } - return NULL; } GC_API void GC_CALL GC_suspend_thread(GC_SUSPEND_THREAD_ID thread) { -- cgit v1.2.1