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
+
1
4
//@ run-pass
2
5
//@ needs-subprocess
3
6
4
- use std:: env;
5
7
use std:: io:: prelude:: * ;
6
8
use std:: process:: Command ;
7
- use std:: thread;
9
+ use std:: { env , thread} ;
8
10
9
11
const THREADS : usize = 20 ;
10
12
const WRITES : usize = 100 ;
@@ -33,14 +35,16 @@ fn parent() {
33
35
}
34
36
35
37
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
+ } )
42
46
} )
43
- } ) . collect :: < Vec < _ > > ( ) ;
47
+ . collect :: < Vec < _ > > ( ) ;
44
48
45
49
for thread in threads {
46
50
thread. join ( ) . unwrap ( ) ;
@@ -63,8 +67,8 @@ fn write_all(buf: &[u8]) {
63
67
fn write_all ( buf : & [ u8 ] ) {
64
68
use std:: fs:: File ;
65
69
use std:: mem;
66
- use std:: os:: windows:: raw:: * ;
67
70
use std:: os:: windows:: prelude:: * ;
71
+ use std:: os:: windows:: raw:: * ;
68
72
69
73
const STD_OUTPUT_HANDLE : u32 = ( -11i32 ) as u32 ;
70
74
You can’t perform that action at this time.
0 commit comments