]> git.lizzy.rs Git - rust.git/blob - thread.rs
76466b2b37beb4b9318e50e146284c75da9fa37a
[rust.git] / thread.rs
1 use crate::env;
2 use crate::sync::atomic::{self, Ordering};
3 use crate::sys::thread as imp;
4
5 pub fn min_stack() -> usize {
6     static MIN: atomic::AtomicUsize = atomic::AtomicUsize::new(0);
7     match MIN.load(Ordering::Relaxed) {
8         0 => {}
9         n => return n - 1,
10     }
11     let amt = env::var("RUST_MIN_STACK").ok().and_then(|s| s.parse().ok());
12     let amt = amt.unwrap_or(imp::DEFAULT_MIN_STACK_SIZE);
13
14     // 0 is our sentinel value, so ensure that we'll never see 0 after
15     // initialization has run
16     MIN.store(amt + 1, Ordering::Relaxed);
17     amt
18 }