2 个版本
0.1.1 | 2023 年 2 月 18 日 |
---|---|
0.1.0 | 2023 年 2 月 18 日 |
#1096 在 并发
22KB
513 行
BBQ:基于块的有限队列,用于数据交换和分析
这是一个支持多个生产者和多个消费者的并发队列。它基于论文 "BBQ:基于块的有限队列,用于数据交换和分析" 实现,可以使用如下方式
用法
将 bbq-rs
添加到您的 Cargo.toml
依赖项中
[dependencies]
bbq-rs = "0.1.1"
示例
use bbq_rs::Bbq;
use bbq_rs::BlockingQueue;
fn main() {
let queue = Bbq::new(100, 100).unwrap();
// Create four producer threads
for i in 0..4 {
let q = queue.clone();
std::thread::spawn(move || {
q.push(i);
});
// Create four consumer threads
for _ in 0..4 {
let q = queue.clone();
std::thread::spawn(move || {
println!("{}", q.pop().unwrap());
});
}
}
依赖项
~130KB