Skip to content

Commit 6ea781d

Browse files
committed
perf(unbounded_mupsic): tail re-check before segment advance to avoid premature exhaustion
1 parent 439ee2c commit 6ea781d

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/lockfreequeues/unbounded_mupsic.nim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,14 @@ proc pop*[S: static int, T; MaxThreads: static int](
274274
if nextSeg == nil:
275275
break
276276

277+
# Tail re-check: a producer may have committed a slot between our
278+
# original `tail` read above and now. Don't advance past data we
279+
# could still pop. Loop back to re-evaluate `seg.head < tail` with
280+
# the fresher tail value before retiring this segment.
281+
let tailRecheck = seg.tail.load(moAcquire)
282+
if seg.head < tailRecheck:
283+
continue
284+
277285
# Single consumer, so no race on headSegment. Advance with release
278286
# semantics and retire under the active pin so a follow-up reclaim
279287
# cannot free this segment until every pinned thread observes the

0 commit comments

Comments
 (0)