A concurrent work-stealing queue for building schedulers.
Distribute some tasks in a thread pool:
```rust use work_queue::{Queue, LocalQueue};
struct Task(Box
let threads = 4;
let queue: Queue
// Push some tasks to the queue. for _ in 0..500 { queue.push(Task(Box::new(|local| { do_work();
local.push(Task(Box::new(|_| do_work())));
local.push(Task(Box::new(|_| do_work())));
})));
}
// Spawn threads to complete the tasks. let handles: Vec<_> = queue .localqueues() .map(|mut localqueue| { std::thread::spawn(move || { while let Some(task) = localqueue.pop() { task.0(&mut localqueue); } }) }) .collect();
for handle in handles { handle.join().unwrap(); } ```
This crate is similar in purpose to crossbeam-deque
, which
also provides concurrent work-stealing queues. However there are a few notable differences:
pop
instead of you having to manually call it.crossbeam-deque
- but the algorithm
itself can be optimized better.crossbeam-deque
which supports local queue
growth. This makes our local queues faster.License: MIT OR Apache-2.0