7 stable releases

2.2.0 Dec 19, 2020
2.1.0 Dec 17, 2020
2.0.0 Jan 1, 2017
1.0.2 Mar 20, 2016

#24 in #lock-free

45 downloads per month

MIT license

53KB
1.5K SLoC

Magnetic

Build Status

Check out the Docs


lib.rs:

Magnetic contains a set of high-performance queues useful for developing low-latency applications. All queues are FIFO unless otherwise specified.

Examples

use std::thread::spawn;
use magnetic::spsc::spsc_queue;
use magnetic::buffer::dynamic::DynamicBuffer;
use magnetic::{Producer, Consumer};

let (p, c) = spsc_queue(DynamicBuffer::new(32).unwrap());

// Push and pop within a single thread
p.push(1).unwrap();
assert_eq!(c.pop(), Ok(1));

// Push and pop from multiple threads. Since this example is using the
// SPSC queue, only one producer and one consumer are allowed.
let t1 = spawn(move || {
    for i in 0..10 {
        println!("Producing {}", i);
        p.push(i).unwrap();
    }
    p
});

let t2 = spawn(move || {
    loop {
        let i = c.pop().unwrap();
        println!("Consumed {}", i);
        if i == 9 { break; }
    }
});

t1.join().unwrap();
t2.join().unwrap();

Dependencies

~120KB