From 4e82bd352d34b476ba8505d85196887743f0c45f Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Tue, 5 Sep 2023 18:39:55 +0100 Subject: [PATCH] Bump the priority of the computer thread As this is responsible for interrupting computers, we should make sure its priority is higher than the background threads. It spends most of its time sleeping, so should be fine. --- .../computercraft/core/computer/ComputerThread.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/projects/core/src/main/java/dan200/computercraft/core/computer/ComputerThread.java b/projects/core/src/main/java/dan200/computercraft/core/computer/ComputerThread.java index 6db6b2896..110961584 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/computer/ComputerThread.java +++ b/projects/core/src/main/java/dan200/computercraft/core/computer/ComputerThread.java @@ -54,7 +54,15 @@ import java.util.concurrent.locks.ReentrantLock; @SuppressWarnings("GuardedBy") // FIXME: Hard to know what the correct thing to do is. public final class ComputerThread { private static final Logger LOG = LoggerFactory.getLogger(ComputerThread.class); - private static final ThreadFactory monitorFactory = ThreadUtils.factory("Computer-Monitor"); + + /** + * A factory for the monitor thread. We want this a slightly higher priority than normal to ensure that the computer + * thread is interrupted. This spends most of it its time idle, so should be safe. + */ + private static final ThreadFactory monitorFactory = ThreadUtils.builder("Computer-Monitor") + .setPriority((Thread.NORM_PRIORITY + Thread.MAX_PRIORITY) / 2) + .build(); + private static final ThreadFactory workerFactory = ThreadUtils.lowPriorityFactory("Computer-Worker"); /**