File tree 2 files changed +14
-1
lines changed
2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,8 @@ impl Thread {
26
26
pub unsafe fn new ( stack : usize , p : Box < dyn FnOnce ( ) > ) -> io:: Result < Thread > {
27
27
let p = Box :: into_raw ( Box :: new ( p) ) ;
28
28
29
+ // CreateThread rounds up values for the stack size to the nearest page size (at least 4kb).
30
+ // If a value of zero is given then the default stack size is used instead.
29
31
let ret = c:: CreateThread (
30
32
ptr:: null_mut ( ) ,
31
33
stack,
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ use crate::mem;
4
4
use crate :: panic:: panic_any;
5
5
use crate :: result;
6
6
use crate :: sync:: {
7
- atomic:: { AtomicBool , Ordering } ,
7
+ atomic:: { AtomicBool , AtomicU8 , Ordering } ,
8
8
mpsc:: { channel, Sender } ,
9
9
Arc , Barrier ,
10
10
} ;
@@ -423,3 +423,14 @@ fn scope_join_race() {
423
423
} ) ;
424
424
}
425
425
}
426
+
427
+ // Test that the smallest value for stack_size works on Windows.
428
+ #[ cfg( windows) ]
429
+ #[ test]
430
+ fn test_minimal_thread_stack ( ) {
431
+ static COUNT : AtomicU8 = AtomicU8 :: new ( 0 ) ;
432
+
433
+ let builder = thread:: Builder :: new ( ) . stack_size ( 1 ) ;
434
+ builder. spawn ( move || COUNT . fetch_add ( 1 , Ordering :: Relaxed ) ) . unwrap ( ) . join ( ) . unwrap ( ) ;
435
+ assert_eq ! ( COUNT . load( Ordering :: Relaxed ) , 1 ) ;
436
+ }
You can’t perform that action at this time.
0 commit comments