Skip to content

Commit

Permalink
Add barrier tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeuw committed May 10, 2022
1 parent a5218f7 commit f04f3e8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/run-pass/concurrency/barrier.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// ignore-windows: Concurrency on Windows is not supported yet.

use std::sync::{Arc, Barrier};
use std::thread;

// Check if Rust barriers are working.

/// This test is taken from the Rust documentation.
/// https://doc.rust-lang.org/stable/std/sync/struct.Barrier.html
fn check_barriers() {
let mut handles = Vec::with_capacity(10);
let barrier = Arc::new(Barrier::new(10));
for _ in 0..10 {
let c = Arc::clone(&barrier);
// The same messages will be printed together.
// You will NOT see any interleaving.
handles.push(thread::spawn(move || {
println!("before wait");
c.wait();
println!("after wait");
}));
}
for handle in handles {
handle.join().unwrap();
}
}

fn main() {
check_barriers();
}
2 changes: 2 additions & 0 deletions tests/run-pass/concurrency/barrier.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
warning: thread support is experimental and incomplete: weak memory effects are not emulated.

20 changes: 20 additions & 0 deletions tests/run-pass/concurrency/barrier.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
before wait
before wait
before wait
before wait
before wait
before wait
before wait
before wait
before wait
before wait
after wait
after wait
after wait
after wait
after wait
after wait
after wait
after wait
after wait
after wait

0 comments on commit f04f3e8

Please sign in to comment.