9 stable releases

2.4.1 Jul 24, 2022
2.4.0 Jul 23, 2022
2.2.0 Dec 19, 2020
2.0.0 Jan 1, 2017
1.0.2 Mar 20, 2016

#545 in Concurrency

Download history 4/week @ 2023-10-16 8/week @ 2023-10-23 24/week @ 2023-10-30 8/week @ 2023-11-06 30/week @ 2023-11-13 26/week @ 2023-11-20 37/week @ 2023-11-27 6/week @ 2023-12-04 17/week @ 2023-12-11 6/week @ 2023-12-18 25/week @ 2023-12-25 15/week @ 2024-01-01 6/week @ 2024-01-08 25/week @ 2024-01-15 10/week @ 2024-01-22 24/week @ 2024-01-29

65 downloads per month

MIT license

50KB
1K SLoC

Magnetic

Crates.io Build Status License

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

More information can be found in 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

~115KB