-
-
Notifications
You must be signed in to change notification settings - Fork 21.7k
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
Avoid deadlocks in multi-threaded management of the C# script map #99539
Avoid deadlocks in multi-threaded management of the C# script map #99539
Conversation
modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs
Outdated
Show resolved
Hide resolved
aad25f5
to
5c94f0b
Compare
modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs
Show resolved
Hide resolved
modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.types.cs
Outdated
Show resolved
Hide resolved
5c94f0b
to
f8f5505
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. As discussed in RC, I believe this PR to be safer than #99798 and according to the author of the other PR it fixes their issue as well.
This PR changes the locking mechanism from lock(obj)
to using a ReaderWriterLockSlim
instance, reducing the chances of a deadlock. The other PR moves NativeFuncs.godotsharp_internal_reload_registered_script(scriptPtr)
outside the lock, and while this also seems to avoid the deadlock it can cause regressions due to underlocking. So this PR seems safer.
I was unable to reproduce the linked issue, but the code looks good to me.
Thanks! |
This didn't fix the issue in my end, any possibility to reopen the issue? Tested with the same MRP and still getting stuck when loading. |
The idea here is that using a read-write locking instead of all-or-nothing reduces the chances of a deadlock.
I'm not sure if this covers every possibility of such, because the interaction between, say, multiple resource loading threads instantiating C# scripts and the .NET module can be complex. All I can say is that this at least stops me from being able to reproduce the issue with the MRP provided.
Note for reviewers: Disable whitespace diff as one of the methods has a change of indentation level that makes the patch look more complex than it actually is.
Fixes #99128.
Fixes #99839 (I haven't been able to reproduce the issue with the MRP, even after modifying it to effectively use multiple loader threads; however, it's extremely likely that the issue the reporter found is fixed by this PR).