-
Notifications
You must be signed in to change notification settings - Fork 206
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
EventWaitHandle
based while loop in bg thread hang on GC in macOS [NativeAOT]
#1560
Comments
This is likely same issue as dotnet/corert#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. |
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(...))
+{
+ Thread.SpinWait(5);
continue;
+} It is a best practice to tell the processor that you are spinwaiting by calling this Spinwait API, so calling 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:
The text was updated successfully, but these errors were encountered: