Commit 124efa23 authored by Maged Michael's avatar Maged Michael Committed by Facebook Github Bot

UnboundedQueue: Fix advanceHead

Summary:
Without the fix multiple consumers may update head concurrently and cause it to lag. If this persists until the destruction time of the queue, some segments may be incorrectly retired twice.

The fix is to wait for head to advance to the current segment first before advancing head to the next segment.

Reviewed By: djwatson

Differential Revision: D6588135

fbshipit-source-id: 3e916441bff5ad3f27de418601990c59a0b89bc2
parent ca3dd9ce
...@@ -500,6 +500,13 @@ class UnboundedQueue { ...@@ -500,6 +500,13 @@ class UnboundedQueue {
auto deadline = std::chrono::steady_clock::time_point::max(); auto deadline = std::chrono::steady_clock::time_point::max();
Segment* next = tryGetNextSegmentUntil(s, deadline); Segment* next = tryGetNextSegmentUntil(s, deadline);
DCHECK(next != nullptr); DCHECK(next != nullptr);
while (head() != s) {
// Wait for head to advance to the current segment first before
// advancing head to the next segment. Otherwise, a lagging
// consumer responsible for advancing head from an earlier
// segment may incorrectly set head back.
asm_volatile_pause();
}
setHead(next); setHead(next);
reclaimSegment(s); reclaimSegment(s);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment