2019-07-26 21:54:25 +00:00
|
|
|
// run-pass
|
|
|
|
|
2018-09-14 10:20:28 +00:00
|
|
|
#![allow(unused_must_use)]
|
|
|
|
#![allow(deprecated)]
|
2016-02-11 11:34:41 +00:00
|
|
|
// ignore-emscripten no threads support
|
2019-04-24 16:26:33 +00:00
|
|
|
// ignore-sgx no processes
|
2016-02-11 11:34:41 +00:00
|
|
|
|
2015-04-03 21:46:54 +00:00
|
|
|
use std::{env, fmt, process, sync, thread};
|
|
|
|
|
|
|
|
struct SlowFmt(u32);
|
|
|
|
impl fmt::Debug for SlowFmt {
|
2018-05-08 23:41:44 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2015-04-03 21:46:54 +00:00
|
|
|
thread::sleep_ms(3);
|
|
|
|
self.0.fmt(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn do_print(x: u32) {
|
|
|
|
let x = SlowFmt(x);
|
|
|
|
println!("{:?}{:?}{:?}{:?}{:?}", x, x, x, x, x);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main(){
|
|
|
|
if env::args().count() == 2 {
|
|
|
|
let barrier = sync::Arc::new(sync::Barrier::new(2));
|
|
|
|
let tbarrier = barrier.clone();
|
2015-04-13 22:15:32 +00:00
|
|
|
let t = thread::spawn(move || {
|
2015-04-03 21:46:54 +00:00
|
|
|
tbarrier.wait();
|
|
|
|
do_print(1);
|
|
|
|
});
|
|
|
|
barrier.wait();
|
|
|
|
do_print(2);
|
|
|
|
t.join();
|
|
|
|
} else {
|
|
|
|
let this = env::args().next().unwrap();
|
|
|
|
let output = process::Command::new(this).arg("-").output().unwrap();
|
|
|
|
for line in String::from_utf8(output.stdout).unwrap().lines() {
|
|
|
|
match line.chars().next().unwrap() {
|
|
|
|
'1' => assert_eq!(line, "11111"),
|
|
|
|
'2' => assert_eq!(line, "22222"),
|
2015-11-02 16:19:27 +00:00
|
|
|
chr => panic!("unexpected character {:?}", chr)
|
2015-04-03 21:46:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|