]> git.lizzy.rs Git - rust.git/blob - src/test/ui/atomic-print.rs
Auto merge of #67000 - spastorino:remove-promoted-from-place, r=oli-obk
[rust.git] / src / test / ui / atomic-print.rs
1 // run-pass
2
3 #![allow(unused_must_use)]
4 #![allow(deprecated)]
5 // ignore-cloudabi no process support
6 // ignore-emscripten no threads support
7 // ignore-sgx no processes
8
9 use std::{env, fmt, process, sync, thread};
10
11 struct SlowFmt(u32);
12 impl fmt::Debug for SlowFmt {
13     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
14         thread::sleep_ms(3);
15         self.0.fmt(f)
16     }
17 }
18
19 fn do_print(x: u32) {
20     let x = SlowFmt(x);
21     println!("{:?}{:?}{:?}{:?}{:?}", x, x, x, x, x);
22 }
23
24 fn main(){
25     if env::args().count() == 2 {
26         let barrier = sync::Arc::new(sync::Barrier::new(2));
27         let tbarrier = barrier.clone();
28         let t = thread::spawn(move || {
29             tbarrier.wait();
30             do_print(1);
31         });
32         barrier.wait();
33         do_print(2);
34         t.join();
35     } else {
36         let this = env::args().next().unwrap();
37         let output = process::Command::new(this).arg("-").output().unwrap();
38         for line in String::from_utf8(output.stdout).unwrap().lines() {
39             match line.chars().next().unwrap() {
40                 '1' => assert_eq!(line, "11111"),
41                 '2' => assert_eq!(line, "22222"),
42                 chr => panic!("unexpected character {:?}", chr)
43             }
44         }
45     }
46 }