-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[marshal] Use a MonoCoopMutex for marshal_mutex #9408
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
Conversation
|
Why is this needed ? The marshal lock is relatively low level lock used to protect hash table accesses etc, how can it block ? |
|
@vargaz There's a stack trace of a deadlock in #9407. Under hybrid suspend, GC s-t-w hangs if Thread A locks the mutex then steps into GC Safe code and is preemptively suspended while Thread B thread is in GC Unsafe (cooperatively suspended) code and also tries to lock and blocks. If the hash table is protected by an OS mutex and the code does a OS mutexes should only be used if it might be taken by threads that aren't attached, or we're doing explicit GC Safe/Unsafe transitions by hand, or we can guarantee that there will be no GC Unsafe->GC Safe transitions while the mutex is locked. Everywhere else it should be a coop mutex. |
|
Coop mutexes are kinda heavyweight, so we should avoid them if possible. In this case, the problem is that the code calls mono_method_signature () which is an api function so it enters unsafe mode, it should call some internal version which doesn't do that. |
|
I think for this specific mutex we can fix it by pulling the call But I don't think your suggestion about We should make But this kind of thing is going to come up again. All non-coop locks are suspect. |
|
Alternatively, the problem is that the code which calls it is in gc safe mode, probably the aot runtime code should transition to gc unsafe mode at the beginning. |
|
Fixes #9407