Function spsc_buffer::spsc_buffer

source ·
pub fn spsc_buffer(size: usize) -> (SpscBufferWriter, SpscBufferReader)
Expand description

Create a new SPSC buffer pair.

The producer and consumer can safely be transferred between threads; the expected use case is that one thread will be writing and one will be reading.

The underlying buffer’s size is synchronised using an atomic. The producer and consumer have methods to query the size and the capacity, which is guaranteed to be consistent between threads but may not be sufficient to prevent races depending on what you are trying to achieve.

See the mio-anonymous-pipes crate for example usage.