Skip to content

Commit 9dbf1d7

Browse files
committed
Fix concurrent_set.c when found garbage object
1 parent f78728f commit 9dbf1d7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

concurrent_set.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,6 @@ rb_concurrent_set_find_or_insert(VALUE *set_obj_ptr, VALUE key, void *data)
610610
RB_VM_LOCKING();
611611
goto retry;
612612
default:
613-
// what about if hash is marked reclaimed but key is not cleared yet
614613
if (curr_hash != hash) {
615614
goto probe_next;
616615
}
@@ -621,8 +620,13 @@ rb_concurrent_set_find_or_insert(VALUE *set_obj_ptr, VALUE key, void *data)
621620
if (continuation) {
622621
goto probe_next;
623622
}
624-
rbimpl_atomic_value_cas(&entry->key, raw_key, CONCURRENT_SET_EMPTY, RBIMPL_ATOMIC_RELEASE, RBIMPL_ATOMIC_RELAXED);
625-
continue;
623+
{
624+
VALUE prev = rbimpl_atomic_value_cas(&entry->key, raw_key, CONCURRENT_SET_EMPTY, RBIMPL_ATOMIC_RELEASE, RBIMPL_ATOMIC_RELAXED);
625+
if (prev == raw_key) {
626+
rbimpl_atomic_sub(&set->size, 1, RBIMPL_ATOMIC_RELAXED);
627+
}
628+
}
629+
continue; // try to reclaim same slot, because the hash is the same and it's now EMPTY
626630
}
627631

628632
if (set->funcs->cmp(key, curr_key)) {

0 commit comments

Comments
 (0)