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]

Create a new wait group.

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.

Mark a thread as having finished.

(This is equivalent to calling add(-1).)

Wait until all threads have completed.

This unblocks when the internal count is 0.

Trait Implementations

impl Clone for WaitGroup
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for WaitGroup
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl Send for WaitGroup

impl Sync for WaitGroup