Skip to content

Commit c001112

Browse files
Fix: Correct conditional lock release w/out acquire (#681)
`index_gt::update` uses conditional `lock(node_try_conditional_lock_)` instead of the hard `lock(node_lock_)` that `index_gt::add` use. When `candidate_slot == updated_slot`, the function deliberately skips `atomic_set`, but it still returns a `node_conditional_lock_t` whose destructor unconditionally calls `atomic_reset`. Closes #680 Co-authored-by: YoungHwi <[email protected]> Co-authored-by: YoungHwi <[email protected]> Co-authored-by: Yoonseok Kim <[email protected]>
1 parent 13c3fd9 commit c001112

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

include/usearch/index.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3836,7 +3836,11 @@ class index_gt {
38363836

38373837
inline node_conditional_lock_t node_try_conditional_lock_(std::size_t slot, bool condition,
38383838
bool& failed_to_acquire) const noexcept {
3839-
failed_to_acquire = condition ? nodes_mutexes_.atomic_set(slot) : false;
3839+
if (!condition) {
3840+
failed_to_acquire = false;
3841+
return {nodes_mutexes_, std::numeric_limits<std::size_t>::max()};
3842+
}
3843+
failed_to_acquire = nodes_mutexes_.atomic_set(slot);
38403844
return {nodes_mutexes_, failed_to_acquire ? std::numeric_limits<std::size_t>::max() : slot};
38413845
}
38423846

0 commit comments

Comments
 (0)