Expand description
DynQueue - a parallel work queue that can grow dynamically while it is drained.
A DynQueue<T> is processed in parallel with DynQueue::for_each_dyn.
The callback is handed a DynQueueHandle with which it can enqueue new Ts.
Those enqueued items are not stuck on the thread that produced them: every
item lives in one shared worklist, and any idle worker drains it. So a workload
that generates more work while running is actually load-balanced across all
threads, unlike a static Rayon split.
§Example
use dynqueue::IntoDynQueue as _;
let out = std::sync::Mutex::new(Vec::new());
vec![1, 2, 3]
.into_dyn_queue()
.for_each_dyn(|handle, value| {
if value == 2 {
handle.enqueue(4)
}
out.lock().unwrap().push(value);
});
let mut result = out.into_inner().unwrap();
result.sort();
assert_eq!(result, vec![1, 2, 3, 4]);§Safety
DynQueueHandle is a borrowing handle: it borrows the queue, so it can only
live inside the callback it was given to and cannot be smuggled out of the
iteration. Trying to retain it is a compile error, not a runtime panic.
Structs§
- DynQueue
- The parallel work queue produced by
IntoDynQueue::into_dyn_queue. - DynQueue
Handle - A handle to enqueue more work into a
DynQueuewhile it is being drained.
Traits§
- Into
DynQueue - Convert a collection into a
DynQueue. - Queue
- The back-end storage a
DynQueueis built on.