Struct chan::WaitGroup
[−]
[src]
pub struct WaitGroup(_);
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()
Methods
impl WaitGroup[src]
pub fn new() -> WaitGroup[src]
Create a new wait group.
pub fn add(&self, delta: i32)[src]
Add a new thread to the waitgroup.
Failure
If the internal count drops below 0 as a result of calling add,
then this function panics.
pub fn done(&self)[src]
Mark a thread as having finished.
(This is equivalent to calling add(-1).)
pub fn wait(&self)[src]
Wait until all threads have completed.
This unblocks when the internal count is 0.
Trait Implementations
impl Clone for WaitGroup[src]
fn clone(&self) -> WaitGroup[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more