From 9a22eaf91a45498a71b3525b3db447bd2b3f05b9 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 1 Oct 2023 16:54:21 -0700 Subject: [PATCH 1/2] Ensure the common thread pool has at least 2 threads. --- chunky/src/java/se/llbit/chunky/main/Chunky.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/chunky/src/java/se/llbit/chunky/main/Chunky.java b/chunky/src/java/se/llbit/chunky/main/Chunky.java index f3b3cb620f..68e74eae3b 100644 --- a/chunky/src/java/se/llbit/chunky/main/Chunky.java +++ b/chunky/src/java/se/llbit/chunky/main/Chunky.java @@ -217,7 +217,8 @@ public static void main(final String[] args) { if (cmdline.mode == CommandLineOptions.Mode.CLI_OPERATION) { exitCode = cmdline.exitCode; } else { - commonThreads = new ForkJoinPool(PersistentSettings.getNumThreads()); + // Initialize the common thread pool. + getCommonThreads(); Chunky chunky = new Chunky(cmdline.options); chunky.headless = cmdline.mode == Mode.HEADLESS_RENDER || cmdline.mode == Mode.CREATE_SNAPSHOT; @@ -341,7 +342,7 @@ public void update() { */ public static ForkJoinPool getCommonThreads() { if (commonThreads == null) { - commonThreads = new ForkJoinPool(PersistentSettings.getNumThreads()); + commonThreads = new ForkJoinPool(Math.max(PersistentSettings.getNumThreads(), 2)); } return commonThreads; } From 3fb6721c398d49ac6880f05d0a885eda165c3ed7 Mon Sep 17 00:00:00 2001 From: Maik Marschner Date: Tue, 3 Oct 2023 14:41:34 +0200 Subject: [PATCH 2/2] Add comment on why we use at least two threads. --- chunky/src/java/se/llbit/chunky/main/Chunky.java | 1 + 1 file changed, 1 insertion(+) diff --git a/chunky/src/java/se/llbit/chunky/main/Chunky.java b/chunky/src/java/se/llbit/chunky/main/Chunky.java index 68e74eae3b..05beadf48d 100644 --- a/chunky/src/java/se/llbit/chunky/main/Chunky.java +++ b/chunky/src/java/se/llbit/chunky/main/Chunky.java @@ -342,6 +342,7 @@ public void update() { */ public static ForkJoinPool getCommonThreads() { if (commonThreads == null) { + // use at least two threads to prevent deadlocks in some java versions (see #1631) commonThreads = new ForkJoinPool(Math.max(PersistentSettings.getNumThreads(), 2)); } return commonThreads;