Dotnet default stack size

Posted by on Wednesday, October 18, 2023

Today I Learned that the default stack size for threads in dotnet e.g. the ThreadPool threads is OS dependent. On Windows it is 1.5 MiB, on Linux, MacOs it is dependent on the concrete OS version. To determine the actual default thread size you have to run ulimit -s. For Ubuntu 22.04 it is 8192 bytes and for macOS 14.2 it is 8176 bytes.

It is possible to configure the default stack size via environment variable e.g. to set the stack to 1.5Mib set DOTNET_DefaultStackSize=180000 (the value is interpreted as hex).