File tree Expand file tree Collapse file tree 1 file changed +14
-10
lines changed
Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Original file line number Diff line number Diff line change 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;
57use std:: io:: prelude:: * ;
68use std:: process:: Command ;
7- use std:: thread;
9+ use std:: { env , thread} ;
810
911const THREADS : usize = 20 ;
1012const WRITES : usize = 100 ;
@@ -33,14 +35,16 @@ fn parent() {
3335}
3436
3537fn 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]) {
6367fn 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
You can’t perform that action at this time.
0 commit comments