-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |