What is the size limit of thread's stack in rust?


#1

I know the size limit of Csharp is 1MB, but what about rust?


#2

My guess would be that it depends on the OS configuration, as in other compiled languages like C and C++. For example, Linux will automatically grow the main thread’s stack until a certain limit is reached, which can to some extent be adjusted using “ulimit”.


#3

You can also explicitly set the stack size when spawning a thread if you want to overwrite the OS’s default: https://doc.rust-lang.org/std/thread/struct.Builder.html#method.stack_size


#4

For spawned threads (other than main) it is whatever value of RUST_MIN_STACK env variable is or implementation defined value. For most implementations, the stack size is 2MB, but it’s 4MB for WebAssembly and 1MB for L4Re due to 1MB being maximum for L4Re.

Min stack is a misleading name, because you can set it to be smaller than that implementation defined value from either Rust source code (when spawning a thread) or using RUST_MIN_STACK environment variable. It’s just a default value, nothing more.