pub struct WaitGroup { /* fields omitted */ }
Enables threads to synchronize the beginning or end of some computation.
WaitGroup
is very similar to Barrier
, but there are a few differences:
-
Barrier
needs to know the number of threads at construction, while WaitGroup
is cloned to
register more threads.
-
A Barrier
can be reused even after all threads have synchronized, while a WaitGroup
synchronizes threads only once.
-
All threads wait for others to reach the Barrier
. With WaitGroup
, each thread can choose
to either wait for other threads or to continue without blocking.
use crossbeam_utils::sync::WaitGroup;
use std::thread;
let wg = WaitGroup::new();
for _ in 0..4 {
let wg = wg.clone();
thread::spawn(move || {
drop(wg);
});
}
wg.wait();
Creates a new wait group and returns the single reference to it.
use crossbeam_utils::sync::WaitGroup;
let wg = WaitGroup::new();
Drops this reference and waits until all other references are dropped.
use crossbeam_utils::sync::WaitGroup;
use std::thread;
let wg = WaitGroup::new();
thread::spawn({
let wg = wg.clone();
move || {
wg.wait();
}
});
wg.wait();
Executes the destructor for this type. Read more
Performs copy-assignment from source
. Read more
Formats the value using the given formatter. Read more
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
type Error = <U as TryFrom<T>>::Error
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static