From 234b1ab14bc5f9ab43df301941aebec03556211b Mon Sep 17 00:00:00 2001 From: yujiasheng <1846100778@qq.com> Date: Tue, 5 Oct 2021 09:43:59 +0800 Subject: [PATCH] fix: should use lock_guard --- ThreadPool.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ThreadPool.h b/ThreadPool.h index 4183203..108741b 100644 --- a/ThreadPool.h +++ b/ThreadPool.h @@ -71,7 +71,7 @@ auto ThreadPool::enqueue(F&& f, Args&&... args) std::future res = task->get_future(); { - std::unique_lock lock(queue_mutex); + std::lock_guard lg(queue_mutex); // don't allow enqueueing after stopping the pool if(stop) @@ -87,7 +87,7 @@ auto ThreadPool::enqueue(F&& f, Args&&... args) inline ThreadPool::~ThreadPool() { { - std::unique_lock lock(queue_mutex); + std::lock_guard lg(queue_mutex); stop = true; } condition.notify_all();