Skip to content

Commit

Permalink
fix: Make ThreadPool only two Threads big
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Aug 5, 2024
1 parent 950ff03 commit ee1e7c9
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -74,7 +74,8 @@ ThreadPool::~ThreadPool() {
std::shared_ptr<ThreadPool> ThreadPool::getSharedPool() {
static std::shared_ptr<ThreadPool> 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<ThreadPool>("nitro-thread", numThreads);
}
return shared;
Expand Down

0 comments on commit ee1e7c9

Please sign in to comment.