#5136·baritone

当两个线程使用 BlockStateOctreeInterface 时,它可能会从错误的分块中返回结果

作者: 0Mattias创建于 2026年9月24日更新于 2026年9月26日

import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicLong;

// Run with: java ChunkCacheRace.java // get0 is BlockStateOctreeInterface.get0 from 1.21.4 without its y range check, with the chunk table stubbed: // chunk (0, 0) is all solid and chunk (1, 0) all air, so every answer has a known right value. // Two threads share one cache and ask about the blocks either side of the border between them. public class ChunkCacheRace {

record StubChunk(boolean solid) {
    boolean isSolid(int x, int y, int z) { return solid; }
}

static final ConcurrentHashMap<Long, StubChunk> TABLE = new ConcurrentHashMap<>();
static {
    TABLE.put(0L, new StubChunk(true));
    TABLE.put(1L, new StubChunk(false));
}

…

内容来源: cabaletta/baritone