std-method

Builder::stack_size: request stack capacity

Request stack capacity for a newly spawned thread. Actual size can be subject to platform minimums and alignment. The example uses a modest request and makes no measurement of allocated stack bytes. Expected stdout (not executed): 8 Common mistake: Assuming a chosen size is exact or eliminates stack-overflow risk.

Formal Syntax & Structure

rust syntaxrust
builder.stack_size(bytes: usize) -> Builder

Working Example

Example Snippetrust
fn main() {    let h = std::thread::Builder::new().stack_size(2 * 1024 * 1024).spawn(|| 8).unwrap();    println!("{}", h.join().unwrap());}
Rust Reference