Skip to content

Commit

Permalink
Fix ann-bench deadlocking on HNSW destruction due to task locks
Browse files Browse the repository at this point in the history
  • Loading branch information
achirkin committed Feb 6, 2025
1 parent 47f5368 commit 2686d62
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions cpp/bench/ann/src/common/thread_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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<void()>([=] { wrapped_f(start, start + items_per_thread); });
futures.push_back(task.task.get_future());
task.has_task = true;
Expand Down

0 comments on commit 2686d62

Please sign in to comment.