Skip to content
/ quickring Public

Yet another lock-free SPSC Ring Buffer (FIFO Queue).

License

Notifications You must be signed in to change notification settings

avhz/quickring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

quickring

This library provides a very fast, lock-free SPSC ring buffer implementation in Rust.

It can perform 1 billion writes and reads in ~1.76s on my MacBook Air M2, on usize data with a capacity of 8192.

Features

  • Very high performance.
  • Generic over any data type.
  • Compile-time static capacity.
  • Split into producer and consumer (SPSC) for concurrent use.

Usage

Run cargo add quickring to add it to your project, or add the following to your Cargo.toml:

[dependencies]
quickring = "*"

Then, you can use it as follows:

use quickring::RingBuffer;

const OPERATIONS: usize = 1_000_000;
const CAPACITY: usize = 1 << 13; // 8192


let rb: RingBuffer<usize, CAPACITY> = RingBuffer::new();
let (mut tx, mut rx) = rb.split();

// Create a producer thread
let producer = std::thread::spawn(move || {
    for i in 0..OPERATIONS {
        while !tx.push(i) {}
    }
});

// Create a consumer thread
let consumer = std::thread::spawn(move || {
    for _ in 0..OPERATIONS {
        loop {
            if let Some(_) = rx.pop() {
                break;
            }
        }
    }
});

producer.join().unwrap();
consumer.join().unwrap();