pub struct WaitGroup(/* private fields */);Expand description
WaitGroup provides synchronization on the completion of threads.
For each thread involved in the synchronization, add(1) should be
called. Just before a thread terminates, it should call done.
To synchronize, call wait, which will block until the number of done
calls corresponds to the number of add(1) calls.
§Example
use std::thread;
let wg = chan::WaitGroup::new();
for _ in 0..4 {
wg.add(1);
let wg = wg.clone();
thread::spawn(move || {
// do some work.
// And now call done.
wg.done();
});
}
// Blocks until `wg.done()` is called for each thread we spawned.
wg.wait()Implementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WaitGroup
impl RefUnwindSafe for WaitGroup
impl Send for WaitGroup
impl Sync for WaitGroup
impl Unpin for WaitGroup
impl UnwindSafe for WaitGroup
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more