Open YoshiRulz opened 2 months ago
On Unix, you can set the default stack size this way:
ulimit -s
shell command. That sets it for the main thread and on glibc based distros for secondary threads too. On MUSL based distros like Alpine, the DOTNET_DefaultStackSize
needs to be used for the secondary threads.On all OSes, but only for secondary threads, since the main thread stack size is set by the OS when launching the application and the runtime cannot influence it.
DOTNET_DefaultStackSize
env variableDEFAULT_STACK_SIZE
property passed to coreclr_initialize
in case you have your own custom .NET hostOn Windows, you can also modify the stack size set in the host executable (if you build your app, you end up having YourApp.exe and YourApp.dll, the .exe is the host)
editbin.exe YourApp.exe /STACK:0x400000
You can also specify the thread stack size when creating new threads in your code in the constructor of the thread (public Thread (System.Threading.ThreadStart start, int maxStackSize)
). However, that doesn't work for threadpool threads.
Tagging subscribers to this area: @mangod9 See info in area-owners.md if you want to be subscribed.
@YoshiRulz is this sufficient for you or would you like something additional?
My team develops on and builds for Windows and Linux, so I think we could use a combination of those 2 workarounds, but it still seems odd that there's no way to change the stack size for the main thread.
edit: I maintain that a compile-time EDITBIN
invocation and a runtime ulimit
invocation are both workarounds. For one, I imagine they can't be used on Android. BASH on macOS might have ulimit
, not sure.
it still seems odd that there's no way to change the stack size for the main thread.
@YoshiRulz there are ways to change it for the main thread both on Windows and Linux that I've mentioned in my previous comment:
ulimit -s
shell command on Linuxeditbin.exe
.@YoshiRulz what's wrong with these ways? The default stack size for the main thread is something only the operating system can set, because it needs to be set before the process is launched and the application itself doesn't have any way to control it.
As per my edit above, they're not cross-platform, and one is compile-time and one is runtime.
If the runtime can't change its own stack size, perhaps it could spawn a new thread with the stack size specified in the assembly metadata (for example) and begin execution of the main method on that thread?
Per discussions at #96347 (there is no official documentation†), the size of the default/global stack is fixed and differs between OSes. ASP.NET devs can use the
stackSize
setting (only with IIS?) to configure it. I would like to do the same with a CLI or desktop app. A new API or an environment variable would also be acceptable for me. I would use this to decrease the size in order to root out stealthy bugs, but I can also see it being used to increase the size for some non-ASP.NET server or other high-perf use case.See also:
† There seemed to be no official documentation for the stack in modern .NET, and info for .NET Framework and Mono was all over the place, so I've collected everything I've found here.