How does Godot handle multiple cores?

AspenforestAspenforest Posts: 1Member
edited June 27 in General Support

Greetings!
I know that Godot supports threads, but AFAIK, running a subthread does not necessarily mean that the thread will be run on a different core. In python, the multiprocessing module, which instantiates separate subprocesses, facilitates the use of multiple cores. I've read some posts about Godot multithreading, but it's not the same thing as multiprocessing, or is it? Please help clarify how Godot runs subthreads and how Godot uses multiple cores of a CPU. Also: if "OS.execute(args)" is executed in a thread, will the process be spawned on another core?

Comments

  • CalinouCalinou Posts: 409Admin Godot Developer
    edited June 29

    I've read some posts about Godot multithreading, but it's not the same thing as multiprocessing, or is it?

    GDScript has actual Thread primitives which will run on any CPU thread made available by the system. There's no GIL like in Python that would hamper this. That said, note that debugging in threads isn't supported yet.

    C# also has threading primitives which you can use in Godot projects.

    Also: if "OS.execute(args)" is executed in a thread, will the process be spawned on another core?

    This can be done even without using a thread. However, you'll need to make the execution non-blocking in this case. If you use a thread, then you can still make the execution blocking. It's up to the OS to make each process run on a CPU core. You can't really control it yourself, except by setting the CPU affinity. Such is the nature of OS-provided core scheduling.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file