-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Mono: Monitor.Enter()
is not interrupted by Thread.Interrupt()
#87718
Comments
Not a regression. Same behavior with mono on net6.0 and net7.0. Works on legacy Mono 6.12.0.188. It looks like we still have the code for async thread interruptions and the WaitSleepJoin thread state. But we don't have this block anymore in dotnet/runtime mono |
That code was removed as part of #47333 I'm not sure if there was some corert-based interruption logic that was wired up that didn't work, or if it worked initially and then we added something before the net6 release that broke it |
@kouvel This is probably going to be hard to fix. The right thing is to finish out #48058 and remove mono's native Monitor implementation in favor of a managed one like NativeAOT. But touching anything related to the sync block causes significant performance perturbations. I think we can probably switch to using a The runtime code for interruptable syscalls is still there, so that part of the native monitor implementation is still functional. It's just that we don't do anything with that information and simply retry the syscall as if we got a spurious interruption. I suppose one thing we can do is call out to managed to |
Made a draft PR that piggybacks on the interruption logic in Mono and calls out to it's not too bad - it won't get called unless the condvar wait syscall is actually interrupted for some reason (most commonly, I think, due to a GC) and calling out to managed is not unreasonable at that point. I will play around with actually replacing native Monitor logic with a managed Lock, too, but I think that's probably too big of a change for net8 at this point |
See
MonitorTests.InterruptWaitTest
undersrc/libraries/System.Threading/tests
(the test is being added by PR #87672):runtime/src/libraries/System.Threading/tests/MonitorTests.cs
Lines 493 to 511 in ed64748
The text was updated successfully, but these errors were encountered: