godotengine / godotengine/godot-cpp
Threading hooks are not exposed
- Dominant language
- C++
- Stars
- 2.7k
- Forks
- 809
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 8
Description
In the Thread class, Godot sets up more things than just running the work function:
https://github.com/godotengine/godot/blob/47ef0549ee490bca066ac00587076f123d973a55/core/os/thread.cpp#L53
Notably, it setups script debugging.
This isn't a problem if an extension uses the `Thread` class, or if you dont plan to run anything Godot-related in that thread.
However it becomes a problem if anything else needs to be used. [WorkedThreadPool](https://github.com/godotengine/godot-cpp/blob/master/include/godot_cpp/templates/thread_work_pool.hpp) for example is pure C++ and does not use Godot objects, therefore it uses `std::thread`, but lacks the hooks Godot is setting up (while the [core implementation](https://github.com/godotengine/godot/blob/master/core/object/worker_thread_pool.h) uses `Thread`). This could lead to unforeseen issues related to the absence of this setup.
If threads come from a third party library, there is also no way to set this up, unless said library allows to re-implement its threads using the `Thread` class. The latter is also a bit inconvenient as it requires the function to run to be a method from a registered Godot object.
Perhaps GDExtension could expose two functions in order to tell Godot when a custom thread starts and ends, so that it can be made aware of them if needed?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.