From 5444848e664b62bfe1c3f98f1550465a55b1e454 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 24 Apr 2023 12:40:40 +0200 Subject: [PATCH] Use a synchronous ThreadLocalAction for killing other threads * That way we have a snapshot fo the currently-running fibers and avoid e.g. scheduling the action on 2 Fibers of the same thread. See the javadoc of Env#submitThreadLocal which say: > Already started synchronous actions will block on activation of a new thread. * Also this means we don't throw the KillException until all currently-running fibers have reached the safepoint. * Note that because of the throw this synchronous action will be exited quickly by all threads once all threads have reached the safepoint. So there is no concern about a nested safepoint or new threads staying blocked a long time. * This was the only ThreadLocalAction which affects multiple Ruby Threads and was asynchronous. (cherry picked from commit 3637300874eb3d9dee0e2acbc5780d846da38537) --- src/main/java/org/truffleruby/core/thread/ThreadManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/truffleruby/core/thread/ThreadManager.java b/src/main/java/org/truffleruby/core/thread/ThreadManager.java index 7eebce51f5a3..44fcbf605c5f 100644 --- a/src/main/java/org/truffleruby/core/thread/ThreadManager.java +++ b/src/main/java/org/truffleruby/core/thread/ThreadManager.java @@ -684,7 +684,7 @@ private void doKillOtherThreads() { context.getSafepointManager().pauseAllThreadsAndExecute( DummyNode.INSTANCE, - new SafepointAction("kill other threads for shutdown", predicate, true, false) { + new SafepointAction("kill other threads for shutdown", predicate, true, true) { @Override public void run(RubyThread rubyThread, Node currentNode) { rubyThread.status = ThreadStatus.ABORTING;