-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
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
Improve thread safety of ScriptServer
#82578
Improve thread safety of ScriptServer
#82578
Conversation
882bc36
to
4f695d6
Compare
4f695d6
to
5f4344b
Compare
I modified this PR to match the expected behaviour of #76586 |
5f4344b
to
d90e320
Compare
Yes, because a GDExtension providing a language can be loaded at runtime. Aside, please have a look at #74501, plus all the related PRs linked there, for some insightful context on the situation of all this. |
So I guess main question now is: Should it be done in #49362 ? |
I think I need to go back to the basics to be sure I can assess this well. There are some issues that will surely require a more comprehensive fix (mutex-protecting the languages array indeed, calling |
If you mean the condition in the current codebase that won't work, it causes a race condition to reappear |
By "the very specific issue," I mean the fact that the thread enter/exit callbacks are not being called at all. But I see that may not be enough a fix. Maybe it's not a bad idea to go full out to do fix the threading issues and protect the languages array, count and the flag (that can become a plain boolean again) with a mutex in this very PR or a subsequent one. It's up to @piiertho. If not, at least I'd like some help to understand why the current changes (beyond fixing the condition) prevent the race. |
The current changes prevents the Which I think is an incomplete solution |
Oh, I see. Then... Well, I'd suggest embracing the mutexed approach and have it fixed for good. |
I tested out a build with some mutexes a week or so ago but don't really have the time to fix with it now so I'll leave it for the OP to work on it if they want |
Hello, sorry for delay. |
Just added some mutex. |
df998b6
to
f12358b
Compare
Forgot clang format, let me fix that |
f12358b
to
73c291c
Compare
Please use clang-format to fix your style |
73c291c
to
faaf49e
Compare
funny thing is that clang format does not find any problem, I had to fix them manually (replacing spaces by tabs). |
Then that's because your clang-format isn't correctly set up, as you still have errors in your format |
faaf49e
to
88f414d
Compare
I'm not suppos to just run |
No, that's for automation, see here |
ScriptServer
What is the reason the Further as confirmed by RandomShaper languages can still be added after initialization, so the original approach to fix this wasn't necessarily sound We can stay safe and keep it, but I'd suggest removing it entirely and rely on the mutex alone |
It is because thread_enter is still called before languages are initialized (I think because WorkerThreadPools are started before |
Any idea on CI failure ? |
It's unrelated, dependency error, being investigated |
Try rebasing your branch, it's quite behind, and some attempts to fix it has been done |
…n languages are initialized
88f414d
to
37651d0
Compare
Seems it does not solve the issue. |
Let's see when we re-run it after all the other CI has passed |
37651d0
to
d636701
Compare
Not sure but I think this patch is not linked to this PR. Or I really don't get why modifying map iterator to add map as a friend class would help. |
I attached the wrong patch. My apologies. This is the right one: |
Sorry for late reply, I've been busy past weeks.
I agree this would be more robust to do the hack in |
Taking the patch as a proof of concept, do you think you could apply it to your PR? The check for the theoretical singleton would be replaced by some equivalent check in the real codebase. If you can do that, I'd just have another request, and this PR would be perfect! Instead of having two booleans, use an enum: enum LanguagesState {
LANGUAGES_STATE_UNINITIALIZED,
LANGUAGES_STATE_INITIALIZED,
LANGUAGES_STATE_TERMINATED,
}; There would be a getter for the status instead of one for any of the booleans. |
Just tried to apply your diff using enums instead of two booleans. |
Can you please share the patch with enums, etc. so I can debug locally and try to polish it? |
Here it is patch.txt |
Please see (and test) #84657. |
Superseded by #84657. Thanks for the contribution! |
When working on godot-jvm multi-threading, we implemented
ScriptLanguage::thread_enter
andScriptLanguage::thread_exit
to attach and detach JVM according to thread lifecycle.Those implementations were not called. So after looking to
ScriptServer
code I found those methods:The problem here is that
languages_finished
is set only when killing languages (C# is usingScriptLanguage::finish
to kill language too).So the problem here is the condition inversion on
This PR fixes this by inverting the condition.
It also adds a pre-processor on this if, as when engine runs language servers are up most of the time.