Expose Thread::is_main_thread()#109779
Merged
Repiteo merged 1 commit intogodotengine:masterfrom Sep 30, 2025
Merged
Conversation
mhilbrunner
approved these changes
Sep 1, 2025
Ivorforce
approved these changes
Sep 12, 2025
Member
There was a problem hiding this comment.
I was thinking, I'd usually rather expose both current thread / current thread ID (get_caller_id) and the main ID (get_main_id) than a method that checks whether they're the same.
But it looks like the logic of is_main_thread is different between implementations, so I'm not sure how easy this would be to achieve. This function sounds useful anyway for GDScript users, so I guess why not expose it.
Contributor
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR exposes
Thread::is_main_thread(), which is already part of Godot's internal API - it's just not exposed to scripts and GDExtension.I found this while working on a GDExtension that runs some code via
RenderingServer.call_on_render_thread(), and it would be useful to know if code is running on the main thread (which if "Thread model" is set to "Safe" would be the same as the render thread, so we can't necessarily check vianot RenderingServer.is_on_render_thread()).But, also, this is used all over the place in Godot modules, so I think it would be useful to GDExtensions in other circumstances as well.