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 |
#711 in Concurrency
50KB
1K
SLoC
Magnetic
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
~110KB