-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Mapgen (mostly) work multithreaded again #9627
Conversation
The general thread unsafeness (in this case: race condition for noise creation) has been present since the very first implementation(s): dcbb953#diff-b4aa9def38b10274e96fd012895653f9R248 |
nice to see you are working on mutithread fixes |
#1755 is mgv6 only, and is not related to threads at all, that is simply the result of how mgv6 is coded to be incompatible with crossing a mapchunk border. For example the mudflow feature alone disallows crossing a mapchunk border. However i accept that generally there may be some weirdness at mapchunk borders and overlapping areas with multiple emerge threads. The code changes in this PR are mostly far beyond my understanding, being code architecture stuff, so i am not qualified approve the code changes, but i can test. |
Looked through the changes, no objections to what you are doing here. |
Right. Any chance you could look into why this happens with mgv7 at some point? |
Ah i did not see the above image earlier, Github was acting strange and not loading some images.
Yes exactly that. All the other non-mgv6 mapgens overgenerate 1 up, 1 down too, do they also do this?
To clarify, are you saying that this PR increases the chances of weirdness with multiple emerge threads, relative to before? Or are you saying the old weirdnesses will just be experienced again? |
Yes, these are existing bugs. This PR just allows you to "experience" them again since
The latter. From my testing it looks like the more emerge threads you use, the higher the likeliness of these bugs reappearing anywhere in the world. |
At least the crash is fixed, for the emerge part i may work on it after this PR is merged to rewrite the emerge workflow which is quite fine but not so easy to understand. |
DO NOT SQUASH WHEN MERGING
Problem: The objects managed by
BiomeManager
,OreManager
,DecorationManager
andSchematicManager
are not thread-safe at all, because:Solution: Create a copy of the managers for each mapgen thread, the implementation of the objects can then freely modify its member variables.
-- Why not teach the implementation to be thread-safe then?
This is unfortunately not as easy and likely requires a larger refactoring*. You can't just e.g. mark the member variables
thread_local
. So instead I opted for creating a copy of everything, which is guaranteed to work fine with the current code.The whole thing is misdesigned anyway, it mixes the ore/deco/... settings (which could easy be constant and shared between all mapgens) with mutable implementation details such as cached noise buffers.
*
ObjDefManager
is also not const correct at all, you can receive mutable references from aconst ObjDefManager&
. This PR does not fix that.Consequences
fixes #8300
It is possible to safely run with
num_emerge_threads > 1
again, though doing so raises the probability of the following appearing again:The infamous y=48 bug
(#1755, #5125)[mgv7, reproducible 100% withnum_emerge_threads = 12
here]General decoration weirdness on chunk boundaries(?)
With more sane thread values (e.g.
num_emerge_threads = 2
), these issues are exceedingly rare. So perhaps multiple emerge threads can be enabled by default again soon.How to test
Test everything related to mapgen, including:
num_emerge_threads
> 1