From 55c206216ea93bd84de8f68b81fd903724006b50 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 26 Feb 2024 17:13:25 -0800 Subject: [PATCH] [Emscripten port] Fix core count logic for Emscripten+pthreads (#6350) Before this all Emscripten builds would use 1 core, but it is important to allow pthreads builds there to use more. --- src/support/threads.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/support/threads.cpp b/src/support/threads.cpp index e61769a849b..58aa05be481 100644 --- a/src/support/threads.cpp +++ b/src/support/threads.cpp @@ -139,15 +139,17 @@ void ThreadPool::initialize(size_t num) { } size_t ThreadPool::getNumCores() { -#ifdef __EMSCRIPTEN__ +#if defined(__EMSCRIPTEN__) && !defined(__EMSCRIPTEN_PTHREADS__) + // In an Emscripten build without pthreads support, avoid the overhead of + // including support code for the below runtime checks. return 1; -#else +#endif + size_t num = std::max(1U, std::thread::hardware_concurrency()); if (getenv("BINARYEN_CORES")) { num = std::stoi(getenv("BINARYEN_CORES")); } return num; -#endif } ThreadPool* ThreadPool::get() {