From 2686d62a7e03eacad671f3f9b3ebcf2e519ee941 Mon Sep 17 00:00:00 2001 From: achirkin Date: Thu, 6 Feb 2025 13:04:12 +0100 Subject: [PATCH] Fix ann-bench deadlocking on HNSW destruction due to task locks --- cpp/bench/ann/src/common/thread_pool.hpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cpp/bench/ann/src/common/thread_pool.hpp b/cpp/bench/ann/src/common/thread_pool.hpp index e2192daea..287ac0a2d 100644 --- a/cpp/bench/ann/src/common/thread_pool.hpp +++ b/cpp/bench/ann/src/common/thread_pool.hpp @@ -60,9 +60,8 @@ class fixed_thread_pool { finished_.store(true, std::memory_order_relaxed); for (unsigned i = 0; i < threads_.size(); ++i) { + // NB: don't lock the task mutex here, may deadlock on .join() otherwise auto& task = tasks_[i]; - std::lock_guard lock(task.mtx); - task.cv.notify_one(); threads_[i].join(); } @@ -105,8 +104,7 @@ class fixed_thread_pool { IdxT start = i * items_per_thread; auto& task = tasks_[i]; { - std::lock_guard lock(task.mtx); - (void)lock; // stop nvcc warning + [[maybe_unused]] std::lock_guard lock(task.mtx); task.task = std::packaged_task([=] { wrapped_f(start, start + items_per_thread); }); futures.push_back(task.task.get_future()); task.has_task = true;