refactor(mpsc): replace the legacy queue backend - #247
Open
mxsm wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
std::sync::mpscbackends with MPSC-owned queue implementations while preserving the public sender, receiver, and error contracts.Syncimplementations and document the bounded slot's localized unsafe invariant.Closes #209.
Design Notes
The unbounded queue keeps sender-visible storage and receiver liveness behind one mutex, while the single receiver moves messages into a local batch to reduce shared-lock contention without introducing unsafe code.
The bounded queue allocates its capacity up front and uses per-slot generation stamps. Producers reserve slots through the tail cursor, while the single consumer advances the head cursor; cache padding prevents producer and consumer cursor updates from sharing a cache line.
Unsafe code is confined to initialized slot access and
Slot<T>: Sync. Each unsafe operation is paired with a documented reservation, publication, acquisition, and reuse invariant, and the queue is exercised under Miri with multiple producers.Validation
cargo x testcargo x checkcargo x miricargo x lintcargo x benchBenchmark Comparison
The following bounded MPSC medians were measured in adjacent runs on the same machine with 16,384 messages per sample.
The existing ecosystem benchmark continues to cover bounded and unbounded channels with 1, 2, 4, and 8 producers. The full benchmark suite completes without an order-of-magnitude regression or a material bounded-contention regression.