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 2MB.

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