diff --git a/Modules/Core/Common/include/itkThreadPool.h b/Modules/Core/Common/include/itkThreadPool.h index ca0be924e8b..821fbd257d8 100644 --- a/Modules/Core/Common/include/itkThreadPool.h +++ b/Modules/Core/Common/include/itkThreadPool.h @@ -93,7 +93,7 @@ auto result = pool->AddWork([](int param) { return param; }, 7); std::future res = task->get_future(); { - std::unique_lock lock(this->GetMutex()); + const std::lock_guard lockGuard(this->GetMutex()); m_WorkQueue.emplace_back([task]() { (*task)(); }); } m_Condition.notify_one(); @@ -107,7 +107,7 @@ auto result = pool->AddWork([](int param) { return param; }, 7); ThreadIdType GetMaximumNumberOfThreads() const { - std::unique_lock lock(this->GetMutex()); + const std::lock_guard lockGuard(this->GetMutex()); return static_cast(m_Threads.size()); } diff --git a/Modules/Core/Common/src/itkThreadPool.cxx b/Modules/Core/Common/src/itkThreadPool.cxx index dfcfc6164ca..57065659fa3 100644 --- a/Modules/Core/Common/src/itkThreadPool.cxx +++ b/Modules/Core/Common/src/itkThreadPool.cxx @@ -122,7 +122,7 @@ ThreadPool::ThreadPool() void ThreadPool::AddThreads(ThreadIdType count) { - std::unique_lock mutexHolder(m_PimplGlobals->m_Mutex); + const std::lock_guard lockGuard(m_PimplGlobals->m_Mutex); m_Threads.reserve(m_Threads.size() + count); for (ThreadIdType i = 0; i < count; ++i) { @@ -139,7 +139,7 @@ ThreadPool::GetMutex() const int ThreadPool::GetNumberOfCurrentlyIdleThreads() const { - std::unique_lock mutexHolder(m_PimplGlobals->m_Mutex); + const std::lock_guard lockGuard(m_PimplGlobals->m_Mutex); return static_cast(m_Threads.size()) - static_cast(m_WorkQueue.size()); // lousy approximation } @@ -148,7 +148,7 @@ ThreadPool::CleanUp() { bool shouldNotify; { - std::unique_lock mutexHolder(m_PimplGlobals->m_Mutex); + const std::lock_guard lockGuard(m_PimplGlobals->m_Mutex); this->m_Stopping = true;