From: Joel Rosdahl Date: Sun, 26 Oct 2025 11:36:26 +0000 (+0100) Subject: fix: Handle util::TaskPool enqueue/shut_down called by different threads X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5fcb190320014baa4e5558dde12609b6f4c8b870;p=thirdparty%2Fccache.git fix: Handle util::TaskPool enqueue/shut_down called by different threads --- diff --git a/src/ccache/util/threadpool.cpp b/src/ccache/util/threadpool.cpp index 107213a5..bffe5ae9 100644 --- a/src/ccache/util/threadpool.cpp +++ b/src/ccache/util/threadpool.cpp @@ -39,9 +39,11 @@ ThreadPool::enqueue(std::function function) { { std::unique_lock lock(m_mutex); - if (m_task_queue.size() >= m_task_queue_max_size) { - m_task_popped_condition.wait( - lock, [this] { return m_task_queue.size() < m_task_queue_max_size; }); + m_task_popped_condition.wait(lock, [this] { + return m_shutting_down || m_task_queue.size() < m_task_queue_max_size; + }); + if (m_shutting_down) { + return; } m_task_queue.emplace(function); } @@ -60,6 +62,7 @@ ThreadPool::shut_down() m_shutting_down = true; } m_task_enqueued_or_shutting_down_condition.notify_all(); + m_task_popped_condition.notify_all(); for (auto& thread : m_worker_threads) { if (thread.joinable()) { thread.join();