Currently ThreadStore::SuspendAllThread in .Net core [1] may can take indefinite time to complete (I am reproducing that under certain conditions with Streets of Rage 4 game). The loop here tries to bring threads into specific internal state which involves suspending thread, and then if it stopped at wrong time resuming it and letting it work a little bit more. There are two problems on this way:
a. That's what this patch is fixing. Thread suspend and resume takes a long time on Wine and without some wait in suspending thread the thread doesn't advance anywhere between resume and next suspend. The linked code considers that SwitchToThread may do nothing on Windows (in fact, that is probably the case most of the time if there is nothing scheduled on the same core like on Linux) and does some wait but only if SwitchToThread correctly returned FALSE indicating that no yield was performed.
b. Another problem is in thread "hijacking" part which doesn't work at all currently with Wine because it relies on correct handling of CONTEXT_EXCEPTION_REQUEST / CONTEXT_EXCEPTION_REPORTING context flags in GetThreadContext(). That hits to much less extent as far as I could observe but also measurably slows down the operation. It is unrelated here, I am working on implementing that.
1. https://github.com/dotnet/corert/blob/c6af4cfc8b625851b91823d9be746c4f7abdc6...