Skip to content

Commit 128b6ab

Browse files
committed
Fix SegmentQueueLCStressTest
1 parent d75d02a commit 128b6ab

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kotlinx-coroutines-core/jvm/test/internal/SegmentBasedQueue.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@ internal class SegmentBasedQueue<T> {
5151
val segmentOrClosed = this.head.findSegmentAndMoveForward(id = deqIdx, startFrom = curHead, createNewSegment = ::createSegment)
5252
if (segmentOrClosed.isClosed) return null
5353
val s = segmentOrClosed.segment
54-
s.cleanPrev()
5554
if (s.id > deqIdx) continue
5655
var el = s.element.value
5756
if (el === null) {
5857
if (s.element.compareAndSet(null, BROKEN)) continue
5958
else el = s.element.value
6059
}
60+
// The link to the previous segment should be cleaned after retrieving the element;
61+
// otherwise, `close()` cannot clean the slot.
62+
s.cleanPrev()
6163
if (el === BROKEN) continue
6264
@Suppress("UNCHECKED_CAST")
6365
return el as T

0 commit comments

Comments
 (0)