From 4ed1d977fcca5922cf8254b1ffbf16cf47b310b4 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Tue, 2 Nov 2021 01:51:43 +0100 Subject: [OS] Add ThreadWorkPool default size to OS. Some platforms (*cough* web *cough*) have hard limits on the number of threads that can be spawned. Currently, ThreadPoolWork (mostly used in rendering/physics servers) will spawn as many threads as CPUs available causing exception on machines with high CPU count. This commit adds a new overridable method to OS that returns the default thread pool size (still the CPU count by default), and overrides it for the JavaScript platform so it always allocate only one thread. We can likely improve the whole ThreadPoolWork in the future to always allocate X amount of threads, and assign jobs to them on the fly, but that will require some more architectural changes. --- core/os/os.h | 1 + 1 file changed, 1 insertion(+) (limited to 'core/os') diff --git a/core/os/os.h b/core/os/os.h index 52bf731501..abfa7ac993 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -298,6 +298,7 @@ public: virtual void set_exit_code(int p_code); virtual int get_processor_count() const; + virtual int get_default_thread_pool_size() const { return get_processor_count(); } virtual String get_unique_id() const; -- cgit v1.2.3