Skip to main content

Crate compact_waitgroup

Crate compact_waitgroup 

Source
Expand description

A compact asynchronous WaitGroup synchronization primitive.

§Usage

§MonoWaitGroup

let (wg, handle) = MonoWaitGroup::new();
assert!(!wg.is_done());
std::thread::spawn(move || {
    // Long-running task
    handle.done();
});
// Wait for the task to complete
wg.await;

§WaitGroup

let (wg, handle) = WaitGroup::new();
let handle_cloned = handle.clone();
assert!(!wg.is_done());
std::thread::spawn(move || {
    // Long-running task
    handle_cloned.done();
});
std::thread::spawn(move || {
    // Another long-running task
    handle.done();
});
// Wait for all tasks to complete
wg.await;

§Memory Layout

This crate is designed to be extremely lightweight. The memory footprint depends on the architecture and the enabled features.

By default, MonoWaitGroup shares the same underlying memory structure as WaitGroup. However, this means MonoWaitGroup carries a usize field for reference counting of workers, which is redundant for the singly-owned MonoWorkerHandle.

Enabling the compact-mono feature changes the internal definition of MonoWaitGroup. It switches to a dedicated, stripped-down layout that removes the reference counter.

ComponentDefault (64-bit)With compact-mono (64-bit)Saving
WaitGroup32 bytes32 bytes0 bytes
MonoWaitGroup32 bytes24 bytes8 bytes

Note:

  • Sizes include the core::task::Waker (16 bytes) and required alignment padding.
  • 32 bytes is often more friendly to global memory allocators.

Structs§

MonoWaitGroup
WaitGroup with a single non-clonable worker handle.
MonoWorkerHandle
Non-clonable worker handle.
WaitGroup
WaitGroup with clonable worker handles.
WorkerHandle
Clonable worker handle.