Skip to content

Commit 7220e52

Browse files
authored
Rollup merge of rust-lang#122088 - ChrisDenton:fixme, r=workingjubilee
Remove unnecessary fixme on new thread stack size As the FIXME itself notes, there's nothing to fix here. And as the documentation for [`CreateThread`] says of `dwStackSize`, the value is rounded up to the nearest page. A 4kb stack is very small but perfectly usable if you're careful. Of course it will be very limited but there's no reason to add artificial limits. We don't know what the user is doing. [`CreateThread`]: https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createthread
2 parents f1354ed + 8718317 commit 7220e52

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

library/std/src/sys/pal/windows/thread.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@ impl Thread {
2626
pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
2727
let p = Box::into_raw(Box::new(p));
2828

29-
// FIXME On UNIX, we guard against stack sizes that are too small but
30-
// that's because pthreads enforces that stacks are at least
31-
// PTHREAD_STACK_MIN bytes big. Windows has no such lower limit, it's
32-
// just that below a certain threshold you can't do anything useful.
33-
// That threshold is application and architecture-specific, however.
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.
3431
let ret = c::CreateThread(
3532
ptr::null_mut(),
3633
stack,

library/std/src/thread/tests.rs

+13
Original file line numberDiff line numberDiff line change
@@ -423,3 +423,16 @@ fn scope_join_race() {
423423
});
424424
}
425425
}
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+
use crate::sync::atomic::AtomicU8;
432+
static COUNT: AtomicU8 = AtomicU8::new(0);
433+
434+
let builder = thread::Builder::new().stack_size(1);
435+
let before = builder.spawn(|| COUNT.fetch_add(1, Ordering::Relaxed)).unwrap().join().unwrap();
436+
assert_eq!(before, 0);
437+
assert_eq!(COUNT.load(Ordering::Relaxed), 1);
438+
}

0 commit comments

Comments
 (0)