Closed ryancheung closed 3 years ago
This is likely same issue as https://github.com/dotnet/corert/issues/8308 . Could you please check whether any other is running in a tight loop?
The previous issue shows the tight loop without break will hang in Windows also. But this new repro works actually in Windows now because I use EventWaitHandle to do synchronization instead of state check in a tight loop. This is how I fix my game run with multitheaded rendering in Windows. But it still hang in macOS. That's why I created this issue.
You can try the repro in Windows and you see it won't hang. The background thread will wait until ui thread sent signal so there should be no tight loop. But it doesn't work in macOS. It still hang on GC.
It is very similar problem, just in a different spot (the tight loop goes through the TryDequeue API).
Here is what we can do quickly to make your game work:
if (!SpriteCommandQueue.TryDequeue(...))
+{
It is a best practice to tell the processor that you are spinwaiting by calling this Spinwait API, so calling `Thread.SpinWait` in a situation like this is goodness.
This change together with my fix should fix the hang.
Please give this a try.
I have opened dotnet/runtime#67805 on the GC suspension problem.
Thanks! It works out of box now.
Given a sample game project. The game has two threads, one is the main (UI) thread. another is a background thread for sending draw commands to main thread. The two thread is synchronised with
EventWaitHandle
.This works out of the box in Windows, but not in macOS.
Repro repo
lldb stacktrace: