Skip to content

Commit 5929120

Browse files
committed
stdio-is-blocking
1 parent cc249a0 commit 5929120

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

tests/ui/io-checks/io-stdout-blocking-writes.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
//! Check that writes to standard output are blocking, ensuring data
2+
//! integrity even with concurrent writes from multiple threads.
3+
14
//@ run-pass
25
//@ needs-subprocess
36

4-
use std::env;
57
use std::io::prelude::*;
68
use std::process::Command;
7-
use std::thread;
9+
use std::{env, thread};
810

911
const THREADS: usize = 20;
1012
const WRITES: usize = 100;
@@ -33,14 +35,16 @@ fn parent() {
3335
}
3436

3537
fn child() {
36-
let threads = (0..THREADS).map(|_| {
37-
thread::spawn(|| {
38-
let buf = [b'a'; WRITE_SIZE];
39-
for _ in 0..WRITES {
40-
write_all(&buf);
41-
}
38+
let threads = (0..THREADS)
39+
.map(|_| {
40+
thread::spawn(|| {
41+
let buf = [b'a'; WRITE_SIZE];
42+
for _ in 0..WRITES {
43+
write_all(&buf);
44+
}
45+
})
4246
})
43-
}).collect::<Vec<_>>();
47+
.collect::<Vec<_>>();
4448

4549
for thread in threads {
4650
thread.join().unwrap();
@@ -63,8 +67,8 @@ fn write_all(buf: &[u8]) {
6367
fn write_all(buf: &[u8]) {
6468
use std::fs::File;
6569
use std::mem;
66-
use std::os::windows::raw::*;
6770
use std::os::windows::prelude::*;
71+
use std::os::windows::raw::*;
6872

6973
const STD_OUTPUT_HANDLE: u32 = (-11i32) as u32;
7074

0 commit comments

Comments
 (0)