Document and test minimal stack size on Windows

This commit is contained in:
Chris Denton 2024-03-06 19:21:34 +00:00
parent 8cd7aaa105
commit 8718317725
No known key found for this signature in database
GPG Key ID: 713472F2F45627DE
2 changed files with 15 additions and 0 deletions

View File

@ -26,6 +26,8 @@ impl Thread {
pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
let p = Box::into_raw(Box::new(p));
// CreateThread rounds up values for the stack size to the nearest page size (at least 4kb).
// If a value of zero is given then the default stack size is used instead.
let ret = c::CreateThread(
ptr::null_mut(),
stack,

View File

@ -423,3 +423,16 @@ fn scope_join_race() {
});
}
}
// Test that the smallest value for stack_size works on Windows.
#[cfg(windows)]
#[test]
fn test_minimal_thread_stack() {
use crate::sync::atomic::AtomicU8;
static COUNT: AtomicU8 = AtomicU8::new(0);
let builder = thread::Builder::new().stack_size(1);
let before = builder.spawn(|| COUNT.fetch_add(1, Ordering::Relaxed)).unwrap().join().unwrap();
assert_eq!(before, 0);
assert_eq!(COUNT.load(Ordering::Relaxed), 1);
}