Skip to content

Commit

Permalink
20364: Fixes issue when using shared objects / dynamically linked lib…
Browse files Browse the repository at this point in the history
…raries where not explicitly setting the number of threads could yield low performance or unexpected behavior (#134)
  • Loading branch information
howsohazard authored May 21, 2024
1 parent f642775 commit b5e400c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Amalgam/ThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ void ThreadPool::SetMaxNumActiveThreads(int32_t new_max_num_active_threads)
{
std::unique_lock<std::mutex> 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;
Expand Down
2 changes: 2 additions & 0 deletions src/Amalgam/ThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b5e400c

Please sign in to comment.