9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-25 18:09:17 +00:00

fix async tracker deadlock

This commit is contained in:
hayanesuru
2025-07-16 13:40:22 +09:00
parent 4dc9f4bebe
commit cdd379f424
4 changed files with 17 additions and 8 deletions

View File

@@ -9,7 +9,7 @@ import java.util.concurrent.locks.LockSupport;
public final class FixedThreadExecutor {
private final Thread[] workers;
private final MpmcQueue<Runnable> channel;
public final MpmcQueue<Runnable> channel;
private static volatile boolean SHUTDOWN = false;
public FixedThreadExecutor(int numThreads, int queue, String prefix) {
@@ -72,12 +72,17 @@ public final class FixedThreadExecutor {
private record Worker(MpmcQueue<Runnable> channel) implements Runnable {
@Override
public void run() {
while (!SHUTDOWN) {
while (true) {
final Runnable task = channel.recv();
if (task != null) {
task.run();
} else if (!SHUTDOWN) {
LockSupport.park();
} else if (SHUTDOWN) {
break;
} else if (channel.isEmpty()) {
Thread.yield();
if (channel.isEmpty()) {
LockSupport.park();
}
}
}
}

View File

@@ -66,6 +66,10 @@ public final class AsyncTracker {
}
public static void onTickEnd(MinecraftServer server) {
if (!TRACKER_EXECUTOR.channel.isEmpty()) {
// not likely
TRACKER_EXECUTOR.unpack();
}
for (ServerLevel world : server.getAllLevels()) {
Future<TrackerCtx>[] task = world.trackerTask;
if (task != null) {