diff --git a/hnswlib/hnswalg.h b/hnswlib/hnswalg.h index 2aff4d48..a97a6540 100644 --- a/hnswlib/hnswalg.h +++ b/hnswlib/hnswalg.h @@ -1099,6 +1099,8 @@ class HierarchicalNSW : public AlgorithmInterface { label_lookup_[label] = cur_c; } + std::unique_lock templock(global); + std::unique_lock lock_el(link_list_locks_[cur_c]); int curlevel = getRandomLevel(mult_); if (level > 0) @@ -1106,7 +1108,6 @@ class HierarchicalNSW : public AlgorithmInterface { element_levels_[cur_c] = curlevel; - std::unique_lock templock(global); int maxlevelcopy = maxlevel_; if (curlevel <= maxlevelcopy) templock.unlock();