Fixes for random lockups on start with Proton #688
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
RE4 now randomly lockups on start under Wine / Proton with REFramework.
The first reason for that (fixed by the first patch) is that when threads are suspended that may happen while they are holding loader lock (due to, e. g., loading or process / thread attaching dlls, i. e., being inside DllMain). That doesn't immediately lock up on Windows as on modern windows GetModuleHandle() and some other queries do not take loader lock but still do so on Wine. Some other cases also take a loader lock though and block while suspended threads hold it, like LoadLibrary, or any newly created thread will block on loader lock before calling DllMain. So it is maybe best to make sure the threads being suspended don't hold loader lock on Windows as well.
The other lockup (fixed by second patch) which is also randomly reproduced is trickier but also related to suspending threads in unfortunate moments (and then creating a new thread locks the creating thread). This is an internal Wine bug which is hard to fix though, but at the same time fix for it in REFramework seems much more straightforward: it is probably no reason to keep the threads suspended until the constructor ends as this suspend doesn't even happen in a generic case (not invoving re4 and re8) and the rest of the constructor works without threads suspension anyway.