Crate spmc_buffer [] [src]

Multi-consumer generalization of triple buffering

This crate is an extension to the triple buffering mechanism proposed as part of triple_buffer, which allows it to work with multiple consumers at the expense of some additional CPU and memory overhead.

Like a triple buffer, the SPMC buffer presented here can be used when a single producer thread is frequently updating a shared data block, which is to be subsequently read by a set of consumer threads. Reading is always wait-free, writing can also be if sufficient storage is allocated.


// Create an SPMC buffer with some initial contents
use spmc_buffer::SPMCBuffer;
let buf = SPMCBuffer::new(2, 1.0);

// Split it into an input and output interface
let (mut buf_input, mut buf_output) = buf.split();

// Create as many extra output interfaces as needed
let mut buf_output2 = buf_output.clone();

// The producer can move a value into the buffer at any time

// A consumer can access the latest value from the producer at any time
let mut latest_value_ref =;
assert_eq!(*latest_value_ref, 4.2);
let latest_value_ref2 =;
assert_eq!(*latest_value_ref2, 4.2);



A single-producer multiple-consumer buffer, useful for thread-safe data sharing in scenarios where triple buffering won't cut it.


Producer interface to SPMC buffers


Consumer interface to SPMC buffers