From afe2e2dae45afb1f243f3e9db66c97011a3b64a2 Mon Sep 17 00:00:00 2001 From: Cade Mack <24661281+cademack@users.noreply.github.com> Date: Mon, 29 Jul 2024 18:03:10 -0400 Subject: [PATCH] 21092: Fixes an issue with (call_sandboxed) where the number of active threads isn't properly protected/edited (#205) Moving the lock of the `threadsMutex` just before `numActiveThreads` is incremented. --- src/Amalgam/ThreadPool.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Amalgam/ThreadPool.cpp b/src/Amalgam/ThreadPool.cpp index 58b7c3b7..1bcfb3aa 100644 --- a/src/Amalgam/ThreadPool.cpp +++ b/src/Amalgam/ThreadPool.cpp @@ -66,13 +66,13 @@ void ThreadPool::AddNewThread() threads.emplace_back( [this] { + std::unique_lock 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 lock(threadsMutex); - //infinite loop waiting for work for(;;) {