diff --git a/src/Amalgam/ThreadPool.cpp b/src/Amalgam/ThreadPool.cpp index 8a39f581..58b7c3b7 100644 --- a/src/Amalgam/ThreadPool.cpp +++ b/src/Amalgam/ThreadPool.cpp @@ -22,6 +22,10 @@ void ThreadPool::SetMaxNumActiveThreads(int32_t new_max_num_active_threads) { std::unique_lock lock(threadsMutex); + //if zero is specified, attempt to get hardware concurrency + if(new_max_num_active_threads == 0) + new_max_num_active_threads = std::thread::hardware_concurrency(); + //don't need to change anything if(new_max_num_active_threads == maxNumActiveThreads || new_max_num_active_threads < 1) return; diff --git a/src/Amalgam/ThreadPool.h b/src/Amalgam/ThreadPool.h index e4ecf3df..5d3ee977 100644 --- a/src/Amalgam/ThreadPool.h +++ b/src/Amalgam/ThreadPool.h @@ -35,6 +35,8 @@ class ThreadPool } //changes the maximum number of active threads + //if max_num_active_threads is 0, it will attempt to ascertain and + //use the number of cores specified by hardware void SetMaxNumActiveThreads(int32_t max_num_active_threads); //returns the current maximum number of threads that are available