std-method

BarrierWaitResult::is_leader: one selected participant

One participant per completed barrier round receives the leader flag. Do not rely on which worker becomes leader. This can assign a single phase-finalization action; a further synchronization may be required before other workers use its result. Expected stdout (not executed): 1 Common mistake: Expecting the first arriving participant to be leader.

Formal Syntax & Structure

rust syntaxrust
barrier.wait().is_leader()

Working Example

Example Snippetrust
fn main() {    use std::sync::Barrier;    let b = Barrier::new(3);    let leaders = std::thread::scope(|s| {        let a = s.spawn(|| b.wait().is_leader() as usize);        let c = s.spawn(|| b.wait().is_leader() as usize);        let main = b.wait().is_leader() as usize;        main + a.join().unwrap() + c.join().unwrap()    });    println!("{leaders}");}
Rust Reference