diff options
| author | David Carlier <devnexen@gmail.com> | 2024-05-26 14:35:26 +0000 |
|---|---|---|
| committer | David Carlier <devnexen@gmail.com> | 2024-05-26 14:35:26 +0000 |
| commit | 073e5d4a2a5eff241b87bafeb636b0c94f2f3f47 (patch) | |
| tree | 4206b98b857958e7e2b51349a7995d76f831bb41 | |
| parent | a6a017d3f3f08228074175aa7125a9ac1c122bcf (diff) | |
| download | rust-073e5d4a2a5eff241b87bafeb636b0c94f2f3f47.tar.gz rust-073e5d4a2a5eff241b87bafeb636b0c94f2f3f47.zip | |
std::pal::unix::thread fetching min stack size on netbsd.
PTHREAD_STACK_MIN is not defined however sysconf/_SC_THREAD_STACK_MIN returns it as it can vary from arch to another.
| -rw-r--r-- | library/std/src/sys/pal/unix/thread.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/library/std/src/sys/pal/unix/thread.rs b/library/std/src/sys/pal/unix/thread.rs index 853ef8736de..1ab54ec57c3 100644 --- a/library/std/src/sys/pal/unix/thread.rs +++ b/library/std/src/sys/pal/unix/thread.rs @@ -717,5 +717,14 @@ unsafe fn min_stack_size(_: *const libc::pthread_attr_t) -> usize { #[cfg(target_os = "netbsd")] unsafe fn min_stack_size(_: *const libc::pthread_attr_t) -> usize { - 2048 // just a guess + static STACK: crate::sync::OnceLock<usize> = crate::sync::OnceLock::new(); + + *STACK.get_or_init(|| { + let mut stack = unsafe { libc::sysconf(libc::_SC_THREAD_STACK_MIN) }; + if stack < 0 { + stack = 2048; // just a guess + } + + stack as usize + }) } |
