pub struct WaitGroup { /* private fields */ }Expand description
A synchronisation barrier: wait for a set of goroutines to complete.
The typical usage pattern is:
use std::sync::Arc;
use go_lib::sync::WaitGroup;
let wg = Arc::new(WaitGroup::new());
for i in 0..5 {
let wg = Arc::clone(&wg);
go_lib::run(move || {
wg.add(1);
// ... spawn goroutine that calls wg.done() when finished ...
});
}
// wg.wait(); // blocks until all Done() calls have been madeImplementations§
Source§impl WaitGroup
impl WaitGroup
Sourcepub fn wait(&self)
pub fn wait(&self)
Block until the counter is zero.
When called from a goroutine: suspends the goroutine back into the
scheduler via gopark so the M and P remain free to run other
goroutines. Resumed by add calling goready when the counter
reaches zero.
When called from a bare OS thread (outside the go-lib scheduler):
blocks the thread on an internal Condvar.
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 UnsafeUnpin 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