From ee1e7c96463607e28e2555092c3ed7b9115624f0 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Mon, 5 Aug 2024 16:36:57 +0200 Subject: [PATCH] fix: Make `ThreadPool` only two Threads big --- .../cpp/threading/ThreadPool.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/react-native-nitro-modules/cpp/threading/ThreadPool.cpp b/packages/react-native-nitro-modules/cpp/threading/ThreadPool.cpp index 162cd0f77..bda4ed224 100644 --- a/packages/react-native-nitro-modules/cpp/threading/ThreadPool.cpp +++ b/packages/react-native-nitro-modules/cpp/threading/ThreadPool.cpp @@ -12,10 +12,10 @@ namespace margelo::nitro { ThreadPool::ThreadPool(const char* name, size_t numThreads) : _isAlive(true), _name(name) { - Logger::log(TAG, "Creating ThreadPool \"%s\" with %ul threads...", name, numThreads); + Logger::log(TAG, "Creating ThreadPool \"%s\" with %i threads...", name, numThreads); for (size_t i = 0; i < numThreads; ++i) { - std::string threadName = std::string(name) + "-" + std::to_string(i); + std::string threadName = std::string(name) + "-" + std::to_string(i + 1); _workers.emplace_back([this, threadName] { // Set the Thread's name ThreadUtils::setThreadName(threadName); @@ -74,7 +74,8 @@ ThreadPool::~ThreadPool() { std::shared_ptr ThreadPool::getSharedPool() { static std::shared_ptr shared; if (shared == nullptr) { - auto numThreads = std::thread::hardware_concurrency(); + int availableThreads = std::thread::hardware_concurrency(); + auto numThreads = std::min(availableThreads, 3); shared = std::make_shared("nitro-thread", numThreads); } return shared;