Struct std::sync::BarrierExperimental
[-]
[+]
[src]
pub struct Barrier { // some fields omitted }
A barrier enables multiple tasks to synchronize the beginning of some computation.
fn main() { use std::sync::{Arc, Barrier}; use std::thread::Thread; let barrier = Arc::new(Barrier::new(10)); for _ in range(0u, 10) { let c = barrier.clone(); // The same messages will be printed together. // You will NOT see any interleaving. Thread::spawn(move|| { println!("before wait"); c.wait(); println!("after wait"); }).detach(); } }use std::sync::{Arc, Barrier}; use std::thread::Thread; let barrier = Arc::new(Barrier::new(10)); for _ in range(0u, 10) { let c = barrier.clone(); // The same messages will be printed together. // You will NOT see any interleaving. Thread::spawn(move|| { println!("before wait"); c.wait(); println!("after wait"); }).detach(); }
Methods
impl Barrier
fn new(n: uint) -> Barrier
Create a new barrier that can block a given number of threads.
A barrier will block n
-1 threads which call wait
and then wake up
all threads at once when the n
th thread calls wait
.
fn wait(&self)
Block the current thread until all threads has rendezvoused here.
Barriers are re-usable after all threads have rendezvoused once, and can be used continuously.