X Tutup
Skip to content

Expose Thread::is_main_thread()#109779

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
dsnopek:thread-is-main-thread
Sep 30, 2025
Merged

Expose Thread::is_main_thread()#109779
Repiteo merged 1 commit intogodotengine:masterfrom
dsnopek:thread-is-main-thread

Conversation

@dsnopek
Copy link
Contributor

@dsnopek dsnopek commented Aug 19, 2025

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 via not 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.

@dsnopek dsnopek added this to the 4.6 milestone Aug 19, 2025
@dsnopek dsnopek requested a review from a team August 19, 2025 15:40
@dsnopek dsnopek requested a review from a team as a code owner August 19, 2025 15:40
@dsnopek dsnopek requested a review from a team as a code owner August 19, 2025 15:40
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me!

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me.

Copy link
Member

@Ivorforce Ivorforce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Repiteo Repiteo merged commit a9d4900 into godotengine:master Sep 30, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Sep 30, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

X Tutup