Skip to content

Commit

Permalink
21092: Fixes an issue with (call_sandboxed) where the number of activ…
Browse files Browse the repository at this point in the history
…e threads isn't properly protected/edited (#205)

Moving the lock of the `threadsMutex` just before `numActiveThreads` is
incremented.
  • Loading branch information
cademack authored Jul 29, 2024
1 parent fa924ff commit afe2e2d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Amalgam/ThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ void ThreadPool::AddNewThread()
threads.emplace_back(
[this]
{
std::unique_lock<std::mutex> lock(threadsMutex);

//count this thread as active during startup
//this is important, as the inner loop assumes the default state of the thread is to count itself
//so the number of threads doesn't change when switching between a completed task and a new one
numActiveThreads++;

std::unique_lock<std::mutex> lock(threadsMutex);

//infinite loop waiting for work
for(;;)
{
Expand Down

0 comments on commit afe2e2d

Please sign in to comment.