Skip to content

Commit

Permalink
std::pal::unix::thread fetching min stack size on netbsd.
Browse files Browse the repository at this point in the history
PTHREAD_STACK_MIN is not defined however sysconf/_SC_THREAD_STACK_MIN
returns it as it can vary from arch to another.
  • Loading branch information
devnexen committed May 26, 2024
1 parent 8981ee4 commit fdcee4d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion std/src/sys/pal/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}

0 comments on commit fdcee4d

Please sign in to comment.