Skip to content

Porting Godot 4: Threading

Caroline Joy Bell edited this page Apr 15, 2024 · 1 revision

Overview

Godot 4 uses multi-threading to run its various servers. As such, low level features, such as threads, semaphores, and mutexes, must be reachable by Godot. Godot, by default, uses the standard C library thread implementation. This means that for a lot of platforms, if programming guidelines are not a concern, multi-threading will "just work" with no extra input from a porter. But, what if your platform has guidelines on how to implement threading, such as on a closed platform?

In Godot 4, there's a struct in the Thread class called PlatformFunctions. It contains settable pointers to functions for setting thread priority, initializing a thread, wrapping a thread, and terminating a thread.

What Must Be Implemented

  • Thread PlatformFunction callbacks:
    • init
    • priority
    • wrap
    • term

What Is Optional