pub struct Barrier { /* private fields */ }
Expand description
Allows for multiple tasks to reach the same point in execution before continuing.
§Examples
const N: usize = 10;
let handles = Vec::new();
let barrier = Barrier::new(N);
for i in 0..N {
spawn(async {
// Every "Before barrier" will be printed before any "After Barrier".
println!("Before Barrier");
barrier.wait().await;
println!("After Barrier");
})
}
for handle in handles {
handle.await;
}
Implementations§
Source§impl Barrier
impl Barrier
Sourcepub const fn new(count: usize) -> Self
pub const fn new(count: usize) -> Self
Create a new barrier that will block count
threads before releasing.
Sourcepub fn wait(&self) -> BarrierWaitFuture<'_> ⓘ
pub fn wait(&self) -> BarrierWaitFuture<'_> ⓘ
Wait for the barrier to be reached by every thread.
A single task will get a BarrierWaitFuture
that resolves to true.
This is the equivalent of the standard library method BarrierWaitResult::is_leader
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Barrier
impl RefUnwindSafe for Barrier
impl Send for Barrier
impl Sync for Barrier
impl Unpin for Barrier
impl UnwindSafe for Barrier
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