Skip to content

Commit

Permalink
Rollup merge of rust-lang#94618 - lewisclark:remove-stack-size-roundi…
Browse files Browse the repository at this point in the history
…ng, r=yaahc

Don't round stack size up for created threads in Windows

Fixes rust-lang#94454

Windows does the rounding itself, so there isn't a need to explicity do the rounding beforehand, as mentioned by `@ChrisDenton` in rust-lang#94454

> The operating system rounds up the specified size to the nearest multiple of the system's allocation granularity (typically 64 KB). To retrieve the allocation granularity of the current system, use the [GetSystemInfo](https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsysteminfo) function.

https://docs.microsoft.com/en-us/windows/win32/procthread/thread-stack-size
  • Loading branch information
Dylan-DPC authored Mar 4, 2022
2 parents 4066434 + 6843dd5 commit 5d038c3
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions library/std/src/sys/windows/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ impl Thread {
// PTHREAD_STACK_MIN bytes big. Windows has no such lower limit, it's
// just that below a certain threshold you can't do anything useful.
// That threshold is application and architecture-specific, however.
// Round up to the next 64 kB because that's what the NT kernel does,
// might as well make it explicit.
let stack_size = (stack + 0xfffe) & (!0xfffe);
let ret = c::CreateThread(
ptr::null_mut(),
stack_size,
stack,
thread_start,
p as *mut _,
c::STACK_SIZE_PARAM_IS_A_RESERVATION,
Expand Down

0 comments on commit 5d038c3

Please sign in to comment.