ServerChunkProvider mixin looks dangerous
embeddedt opened this issue ยท 1 comments
While writes to the mbdLastChunk(Pos)
arrays are synchronized, reads are not. If one thread is mutating the cache in storeInCache
, there is a possibility a second thread could read an updated value for mbdLastChunkPos
but still read the old chunk from mbdLastChunk
. This will probably result in some obscure failure later down the line.
Personally, I would suggest doing the caching at a higher level in whatever worker threads are being used, rather than modifying the game's chunk provider. You could use the Forge event to be notified when the chunk unloads and invalidate the cache. I think it would be much cleaner and less likely to cause issues.