|0.3.0||Nov 12, 2023|
|0.2.3||Dec 13, 2022|
|0.2.2||Mar 4, 2022|
|0.2.0||Sep 20, 2021|
|0.1.1||Nov 20, 2020|
#40 in Concurrency
80,367 downloads per month
Used in 26 crates (12 directly)
Real-Time Ring Buffer
A wait-free single-producer single-consumer (SPSC) ring buffer for Rust.
This crate can be used without the standard library (
by disabling the
std feature (which is enabled by default),
but the alloc crate is needed nevertheless.
Add this to your
[dependencies] rtrb = "0.3"
For a list of breaking changes and for instructions how to upgrade between released versions, have a look at the changelog.
Running the tests:
Testing the benchmarks (without actually benchmarking):
cargo test --benches
Running the benchmarks (using the criterion crate;
results will be available in
Creating the HTML docs (which will be available in
To measure code coverage, nightly Rust is required, as well as a few additional dependencies:
rustup toolchain install nightly rustup component add llvm-tools-preview cargo install grcov
Test coverage data can be obtained and analyzed with these commands:
cargo clean RUSTFLAGS="-Z instrument-coverage" RUSTDOCFLAGS="-Z instrument-coverage -Z unstable-options --persist-doctests target/debug/doctestbins" LLVM_PROFILE_FILE="coverage/%p-%m.profraw" cargo +nightly test grcov coverage --source-dir . --binary-path target/debug --output-type html --output-path coverage
The last command creates an HTML report in
Testing with Miri also needs nightly Rust:
cargo +nightly miri test
Running the tests with ThreadSanitizer requires nightly Rust as well:
RUSTFLAGS="-Z sanitizer=thread" cargo +nightly test --tests -Z build-std --target x86_64-unknown-linux-gnu
You might have to adapt the
--target option to your system (see e.g.
This crate's minimum supported
rustc version (MSRV) is
The MSRV is not expected to be updated frequently, but if it is,
there will be (at least) a minor version bump.
The initial code has been ripped off of https://github.com/crossbeam-rs/crossbeam/pull/338, with permission of the PR author.
It has been isolated from the rest of
crossbeam with git-filter-repo:
git-filter-repo --subdirectory-filter crossbeam-queue --path src/spsc.rs --path tests/spsc.rs --refs refs/heads/spsc
If you don't like this crate, no problem, there are several alternatives for you to choose from. There are many varieties of ring buffers available, here we limit the selection to wait-free SPSC implementations:
- fixed-queue (using const generics, see
- heapless (for embedded systems, see
- jack (FFI bindings for JACK, see
- magnetic (see
- npnc (see
- ringbuf (supports const generics and heap allocation)
- ringbuffer-spsc (using const generics)
- shmem-ipc (see
There are also implementations in other languages:
- boost::lockfree::spsc_queue (C++)
- folly::ProducerConsumerQueue (C++)
- JACK ring buffer (C)
- PortAudio ring buffer (C)
- readerwriterqueue (C++)
- SPSCQueue (C++)
If you know more alternatives for this list, please open an issue.
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.