0 votes

Need to know if threading in Godot is preemptive or cooperative and it is different on different platforms?

Thanks.

Godot version 3.2.3
in Engine by (30 points)

Until now i didn't even know cooperative threading was a thing. Thanks for asking this question.

Preemptive or cooperative using what viewpoint? Are you asking whether GDScript Threads are actual native operating system threads/processes or whether Godot handles the scheduling itself and actually runs all GDScript code in a single OS thread? Or do you actually want to know whether GDscript threads need to cooperate to each get runtime? Because if you're interested in the latter, you can just answer your own question by creating and starting two threads that print something to the console every few seconds and looking whether they both print concurrently.

I'm specifically interested in knowing what model GDScript threading uses.

1 Answer

0 votes

and it is different on different platforms?

Since Godot 3.3, Godot uses std::mutex and other threading primitives from the C++ standard library. Their implementation is OS-specific. Official Windows binaries are compiled with MinGW using the POSIX thread model (pthreads). Win32 threads aren't supported by Godot when compiling with MinGW, but they are when compiling with MSVC.

by (9,328 points)

Thanks for the info. In the absence of any other answer, I'll assume cooperative multi-threading and structure my code appropriately.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.