From 57fe00b359d70b8e4c4ca75d093c3afc9a7eed62 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Thu, 6 Nov 2025 16:39:25 -0800 Subject: [PATCH 01/11] Document DOTNET_Thread_DefaultStackSize environment variable --- docs/core/runtime-config/threading.md | 266 ++------------------------ 1 file changed, 20 insertions(+), 246 deletions(-) diff --git a/docs/core/runtime-config/threading.md b/docs/core/runtime-config/threading.md index b2806433ca0a2..84c08bae536ac 100644 --- a/docs/core/runtime-config/threading.md +++ b/docs/core/runtime-config/threading.md @@ -2,266 +2,40 @@ title: Threading config settings description: Learn about the settings that configure threading for .NET apps. ms.date: 11/04/2021 +ai-usage: ai-assisted --- -# Runtime configuration options for threading - -This article details the settings you can use to configure threading in .NET. - -[!INCLUDE [complus-prefix](../../../includes/complus-prefix.md)] - -## Use all CPU groups on Windows - -- On machines that have multiple CPU groups, this setting configures whether components such as the thread pool use all CPU groups or only the primary CPU group of the process. The setting also affects what returns. -- When this setting is enabled, all CPU groups are used and threads are also [automatically distributed across CPU groups](#assign-threads-to-cpu-groups-on-windows) by default. -- This setting is enabled by default on Windows 11 and later versions, and disabled by default on Windows 10 and earlier versions. For this setting to take effect when enabled, the GC must also be configured to use all CPU groups; for more information, see [GC CPU groups](./garbage-collector.md#cpu-groups). - -| | Setting name | Values | -| - | - | - | -| **runtimeconfig.json** | N/A | N/A | -| **Environment variable** | `COMPlus_Thread_UseAllCpuGroups` or `DOTNET_Thread_UseAllCpuGroups` | `0` - disabled
`1` - enabled | - -## Assign threads to CPU groups on Windows - -- On machines that have multiple CPU groups and [all CPU groups are being used](#use-all-cpu-groups-on-windows), this setting configures whether threads are automatically distributed across CPU groups. -- When this setting is enabled, new threads are assigned to a CPU group in a way that tries to fully populate a CPU group that is already in use before utilizing a new CPU group. -- This setting is enabled by default. - -| | Setting name | Values | -| - | - | - | -| **runtimeconfig.json** | N/A | N/A | -| **Environment variable** | `COMPlus_Thread_AssignCpuGroups` or `DOTNET_Thread_AssignCpuGroups` | `0` - disabled
`1` - enabled | - -## Minimum threads - -- Specifies the minimum number of threads for the worker thread pool. -- Corresponds to the method. - -| | Setting name | Values | -| - | - | - | -| **runtimeconfig.json** | `System.Threading.ThreadPool.MinThreads` | An integer that represents the minimum number of threads | -| **MSBuild property** | `ThreadPoolMinThreads` | An integer that represents the minimum number of threads | -| **Environment variable** | N/A | N/A | - -### Examples - -*runtimeconfig.json* file: - -```json -{ - "runtimeOptions": { - "configProperties": { - "System.Threading.ThreadPool.MinThreads": 4 - } - } -} -``` - -*runtimeconfig.template.json* file: - -```json -{ - "configProperties": { - "System.Threading.ThreadPool.MinThreads": 4 - } -} -``` - -Project file: - -```xml - - - - 4 - - - -``` - -## Maximum threads - -- Specifies the maximum number of threads for the worker thread pool. -- Corresponds to the method. - -| | Setting name | Values | -| - | - | - | -| **runtimeconfig.json** | `System.Threading.ThreadPool.MaxThreads` | An integer that represents the maximum number of threads | -| **MSBuild property** | `ThreadPoolMaxThreads` | An integer that represents the maximum number of threads | -| **Environment variable** | N/A | N/A | - -### Examples - -*runtimeconfig.json* file: - -```json -{ - "runtimeOptions": { - "configProperties": { - "System.Threading.ThreadPool.MaxThreads": 20 - } - } -} -``` - -*runtimeconfig.template.json* file: - -```json -{ - "configProperties": { - "System.Threading.ThreadPool.MaxThreads": 20 - } -} -``` - -Project file: - -```xml - - - 20 - - - -``` - -## Windows thread pool - -- For projects on Windows, configures whether thread pool thread management is delegated to the Windows thread pool. -- If you omit this setting or the platform is not Windows, the .NET thread pool is used instead. -- Only applications published with Native AOT on Windows use the Windows thread pool by default, for which you can opt to use the .NET thread pool instead by disabling the config setting. -- The Windows thread pool may perform better in some cases, such as in cases where the minimum number of threads is configured to a high value, or when the Windows thread pool is already being heavily used by the app. There may also be cases where the .NET thread pool performs better, such as in heavy I/O handling on larger machines. It's advisable to check performance metrics when changing this config setting. -- Some APIs are not supported when using the Windows thread pool, such as , , and . Thread pool config settings for minimum and maximum threads are also not effective. An alternative to is the class. - -| | Setting name | Values | Version introduced | -| - | - | - | - | -| **runtimeconfig.json** | `System.Threading.ThreadPool.UseWindowsThreadPool` | `true` - enabled
`false` - disabled | .NET 8 | -| **MSBuild property** | `UseWindowsThreadPool` | `true` - enabled
`false` - disabled | .NET 8 | -| **Environment variable** | `DOTNET_ThreadPool_UseWindowsThreadPool` | `1` - enabled
`0` - disabled | .NET 8 | - -### Examples - -*runtimeconfig.json* file: - -```json -{ - "runtimeOptions": { - "configProperties": { - "System.Threading.ThreadPool.UseWindowsThreadPool": true - } - } -} -``` - -*runtimeconfig.template.json* file: - -```json -{ - "configProperties": { - "System.Threading.ThreadPool.UseWindowsThreadPool": true - } -} -``` - -Project file: - -```xml - - - - true - - - -``` - -## Thread injection in response to blocking work items - -In some cases, the thread pool detects work items that block its threads. To compensate, it injects more threads. In .NET 6+, you can use the following [runtime configuration](https://github.com/dotnet/docs/blob/main/docs/core/runtime-config/index.md) settings to configure thread injection in response to blocking work items. Currently, these settings take effect only for work items that wait for another task to complete, such as in typical [sync-over-async](https://devblogs.microsoft.com/pfxteam/should-i-expose-synchronous-wrappers-for-asynchronous-methods/) cases. - -| *runtimeconfig.json* setting name | Description | Version introduced | -| - | - | - | -| `System.Threading.ThreadPool.Blocking.ThreadsToAddWithoutDelay_ProcCountFactor` | After the thread count based on `MinThreads` is reached, this value (after it is multiplied by the processor count) specifies how many additional threads may be created without a delay. | .NET 6 | -| `System.Threading.ThreadPool.Blocking.ThreadsPerDelayStep_ProcCountFactor` | After the thread count based on `ThreadsToAddWithoutDelay` is reached, this value (after it is multiplied by the processor count) specifies after how many threads an additional `DelayStepMs` would be added to the delay before each new thread is created. | .NET 6 | -| `System.Threading.ThreadPool.Blocking.DelayStepMs` | After the thread count based on `ThreadsToAddWithoutDelay` is reached, this value specifies how much additional delay to add per `ThreadsPerDelayStep` threads, which would be applied before each new thread is created. | .NET 6 | -| `System.Threading.ThreadPool.Blocking.MaxDelayMs` | After the thread count based on `ThreadsToAddWithoutDelay` is reached, this value specifies the max delay to use before each new thread is created. | .NET 6 | -| `System.Threading.ThreadPool.Blocking.IgnoreMemoryUsage` | By default, the rate of thread injection in response to blocking is limited by heuristics that determine whether there is sufficient physical memory available. In some situations, it may be preferable to inject threads more quickly even in low-memory situations. You can disable the memory usage heuristics by turning off this switch. | .NET 7 | - -### How the configuration settings take effect - -- After the thread count based on `MinThreads` is reached, up to `ThreadsToAddWithoutDelay` additional threads may be created without a delay. -- After that, before each additional thread is created, a delay is induced, starting with `DelayStepMs`. -- For every `ThreadsPerDelayStep` threads that are added with a delay, an additional `DelayStepMs` is added to the delay. -- The delay may not exceed `MaxDelayMs`. -- Delays are only induced before creating threads. If threads are already available, they would be released without delay to compensate for blocking work items. -- Physical memory usage and limits are also used and, beyond a threshold, the system switches to slower thread injection. - -### Examples - -*runtimeconfig.json* file: - -```json -{ - "runtimeOptions": { - "configProperties": { - "System.Threading.ThreadPool.Blocking.ThreadsToAddWithoutDelay_ProcCountFactor": 5 - } - } -} -``` - -*runtimeconfig.template.json* file: +# Runtime configuration options for threading -```json -{ - "configProperties": { - "System.Threading.ThreadPool.Blocking.ThreadsToAddWithoutDelay_ProcCountFactor": 5 - } -} -``` +... -## `AutoreleasePool` for managed threads +## Default stack size for new threads -This option configures whether each managed thread receives an implicit [NSAutoreleasePool](https://developer.apple.com/documentation/foundation/nsautoreleasepool) when running on a supported macOS platform. +- Specifies the stack size (in bytes) for new VM threads that are created with the default stack size. +- This setting allows configuration of the stack size for threads created by and other APIs that do not manually specify a stack size. +- If not set, the stack size is determined by the system or runtime default. | | Setting name | Values | Version introduced | | - | - | - | - | -| **runtimeconfig.json** | `System.Threading.Thread.EnableAutoreleasePool` | `true` or `false` | .NET 6 | -| **MSBuild property** | `AutoreleasePoolSupport` | `true` or `false` | .NET 6 | -| **Environment variable** | N/A | N/A | N/A | +| **Environment variable** | `DOTNET_Thread_DefaultStackSize` | An integer value (bytes). Example: `1048576` for 1 MB | .NET 9 | ### Examples -*runtimeconfig.json* file: +Set the stack size to 2 MB for all new threads: -```json -{ - "runtimeOptions": { - "configProperties": { - "System.Threading.Thread.EnableAutoreleasePool": true - } - } -} +#### On Windows, Linux, or macOS: +```shell +export DOTNET_Thread_DefaultStackSize=2097152 +dotnet myapp.dll ``` -*runtimeconfig.template.json* file: - -```json -{ - "configProperties": { - "System.Threading.Thread.EnableAutoreleasePool": true - } -} +#### In C# code (for reference, no runtimeconfig property): +```csharp +// Stack size is determined by the DOTNET_Thread_DefaultStackSize environment variable +var thread = new Thread(() => { /* thread logic */ }); +thread.Start(); ``` -Project file: - -```xml - +**Note:** This setting does not affect threads for which a non-default stack size is specified at creation. - - true - - - -``` +... \ No newline at end of file From f693aca60f3c9215d7209e768f66c14ad53f4a89 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 7 Nov 2025 00:39:46 +0000 Subject: [PATCH 02/11] Initial plan From 6379675e4e1988b56215cbe77afb1e1440ff3450 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 7 Nov 2025 00:45:54 +0000 Subject: [PATCH 03/11] Fix markdown linting issues in threading.md Co-authored-by: agocke <515774+agocke@users.noreply.github.com> --- docs/core/runtime-config/threading.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/core/runtime-config/threading.md b/docs/core/runtime-config/threading.md index 84c08bae536ac..5e38d70366501 100644 --- a/docs/core/runtime-config/threading.md +++ b/docs/core/runtime-config/threading.md @@ -24,12 +24,14 @@ ai-usage: ai-assisted Set the stack size to 2 MB for all new threads: #### On Windows, Linux, or macOS: + ```shell export DOTNET_Thread_DefaultStackSize=2097152 dotnet myapp.dll ``` #### In C# code (for reference, no runtimeconfig property): + ```csharp // Stack size is determined by the DOTNET_Thread_DefaultStackSize environment variable var thread = new Thread(() => { /* thread logic */ }); @@ -38,4 +40,4 @@ thread.Start(); **Note:** This setting does not affect threads for which a non-default stack size is specified at creation. -... \ No newline at end of file +... From 25a138bf2a1b4186b8b5f24d031fecb75a1ea918 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 7 Nov 2025 17:45:30 +0000 Subject: [PATCH 04/11] Remove placeholder ellipses from threading.md Co-authored-by: agocke <515774+agocke@users.noreply.github.com> --- docs/core/runtime-config/threading.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/docs/core/runtime-config/threading.md b/docs/core/runtime-config/threading.md index 5e38d70366501..f0acf320a05db 100644 --- a/docs/core/runtime-config/threading.md +++ b/docs/core/runtime-config/threading.md @@ -7,8 +7,6 @@ ai-usage: ai-assisted # Runtime configuration options for threading -... - ## Default stack size for new threads - Specifies the stack size (in bytes) for new VM threads that are created with the default stack size. @@ -39,5 +37,3 @@ thread.Start(); ``` **Note:** This setting does not affect threads for which a non-default stack size is specified at creation. - -... From db3f8b3a940cbbc6584976beb318ef658c539f33 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 7 Nov 2025 18:01:59 +0000 Subject: [PATCH 05/11] Add DOTNET_Thread_DefaultStackSize section to existing content Co-authored-by: agocke <515774+agocke@users.noreply.github.com> --- docs/core/runtime-config/threading.md | 262 +++++++++++++++++++++++++- 1 file changed, 261 insertions(+), 1 deletion(-) diff --git a/docs/core/runtime-config/threading.md b/docs/core/runtime-config/threading.md index f0acf320a05db..b4e18dda2f539 100644 --- a/docs/core/runtime-config/threading.md +++ b/docs/core/runtime-config/threading.md @@ -4,9 +4,269 @@ description: Learn about the settings that configure threading for .NET apps. ms.date: 11/04/2021 ai-usage: ai-assisted --- - # Runtime configuration options for threading +This article details the settings you can use to configure threading in .NET. + +[!INCLUDE [complus-prefix](../../../includes/complus-prefix.md)] + +## Use all CPU groups on Windows + +- On machines that have multiple CPU groups, this setting configures whether components such as the thread pool use all CPU groups or only the primary CPU group of the process. The setting also affects what returns. +- When this setting is enabled, all CPU groups are used and threads are also [automatically distributed across CPU groups](#assign-threads-to-cpu-groups-on-windows) by default. +- This setting is enabled by default on Windows 11 and later versions, and disabled by default on Windows 10 and earlier versions. For this setting to take effect when enabled, the GC must also be configured to use all CPU groups; for more information, see [GC CPU groups](./garbage-collector.md#cpu-groups). + +| | Setting name | Values | +| - | - | - | +| **runtimeconfig.json** | N/A | N/A | +| **Environment variable** | `COMPlus_Thread_UseAllCpuGroups` or `DOTNET_Thread_UseAllCpuGroups` | `0` - disabled
`1` - enabled | + +## Assign threads to CPU groups on Windows + +- On machines that have multiple CPU groups and [all CPU groups are being used](#use-all-cpu-groups-on-windows), this setting configures whether threads are automatically distributed across CPU groups. +- When this setting is enabled, new threads are assigned to a CPU group in a way that tries to fully populate a CPU group that is already in use before utilizing a new CPU group. +- This setting is enabled by default. + +| | Setting name | Values | +| - | - | - | +| **runtimeconfig.json** | N/A | N/A | +| **Environment variable** | `COMPlus_Thread_AssignCpuGroups` or `DOTNET_Thread_AssignCpuGroups` | `0` - disabled
`1` - enabled | + +## Minimum threads + +- Specifies the minimum number of threads for the worker thread pool. +- Corresponds to the method. + +| | Setting name | Values | +| - | - | - | +| **runtimeconfig.json** | `System.Threading.ThreadPool.MinThreads` | An integer that represents the minimum number of threads | +| **MSBuild property** | `ThreadPoolMinThreads` | An integer that represents the minimum number of threads | +| **Environment variable** | N/A | N/A | + +### Examples + +*runtimeconfig.json* file: + +```json +{ + "runtimeOptions": { + "configProperties": { + "System.Threading.ThreadPool.MinThreads": 4 + } + } +} +``` + +*runtimeconfig.template.json* file: + +```json +{ + "configProperties": { + "System.Threading.ThreadPool.MinThreads": 4 + } +} +``` + +Project file: + +```xml + + + + 4 + + + +``` + +## Maximum threads + +- Specifies the maximum number of threads for the worker thread pool. +- Corresponds to the method. + +| | Setting name | Values | +| - | - | - | +| **runtimeconfig.json** | `System.Threading.ThreadPool.MaxThreads` | An integer that represents the maximum number of threads | +| **MSBuild property** | `ThreadPoolMaxThreads` | An integer that represents the maximum number of threads | +| **Environment variable** | N/A | N/A | + +### Examples + +*runtimeconfig.json* file: + +```json +{ + "runtimeOptions": { + "configProperties": { + "System.Threading.ThreadPool.MaxThreads": 20 + } + } +} +``` + +*runtimeconfig.template.json* file: + +```json +{ + "configProperties": { + "System.Threading.ThreadPool.MaxThreads": 20 + } +} +``` + +Project file: + +```xml + + + + 20 + + + +``` + +## Windows thread pool + +- For projects on Windows, configures whether thread pool thread management is delegated to the Windows thread pool. +- If you omit this setting or the platform is not Windows, the .NET thread pool is used instead. +- Only applications published with Native AOT on Windows use the Windows thread pool by default, for which you can opt to use the .NET thread pool instead by disabling the config setting. +- The Windows thread pool may perform better in some cases, such as in cases where the minimum number of threads is configured to a high value, or when the Windows thread pool is already being heavily used by the app. There may also be cases where the .NET thread pool performs better, such as in heavy I/O handling on larger machines. It's advisable to check performance metrics when changing this config setting. +- Some APIs are not supported when using the Windows thread pool, such as , , and . Thread pool config settings for minimum and maximum threads are also not effective. An alternative to is the class. + +| | Setting name | Values | Version introduced | +| - | - | - | - | +| **runtimeconfig.json** | `System.Threading.ThreadPool.UseWindowsThreadPool` | `true` - enabled
`false` - disabled | .NET 8 | +| **MSBuild property** | `UseWindowsThreadPool` | `true` - enabled
`false` - disabled | .NET 8 | +| **Environment variable** | `DOTNET_ThreadPool_UseWindowsThreadPool` | `1` - enabled
`0` - disabled | .NET 8 | + +### Examples + +*runtimeconfig.json* file: + +```json +{ + "runtimeOptions": { + "configProperties": { + "System.Threading.ThreadPool.UseWindowsThreadPool": true + } + } +} +``` + +*runtimeconfig.template.json* file: + +```json +{ + "configProperties": { + "System.Threading.ThreadPool.UseWindowsThreadPool": true + } +} +``` + +Project file: + +```xml + + + + true + + + +``` + +## Thread injection in response to blocking work items + +In some cases, the thread pool detects work items that block its threads. To compensate, it injects more threads. In .NET 6+, you can use the following [runtime configuration](https://github.com/dotnet/docs/blob/main/docs/core/runtime-config/index.md) settings to configure thread injection in response to blocking work items. Currently, these settings take effect only for work items that wait for another task to complete, such as in typical [sync-over-async](https://devblogs.microsoft.com/pfxteam/should-i-expose-synchronous-wrappers-for-asynchronous-methods/) cases. + +| *runtimeconfig.json* setting name | Description | Version introduced | +| - | - | - | +| `System.Threading.ThreadPool.Blocking.ThreadsToAddWithoutDelay_ProcCountFactor` | After the thread count based on `MinThreads` is reached, this value (after it is multiplied by the processor count) specifies how many additional threads may be created without a delay. | .NET 6 | +| `System.Threading.ThreadPool.Blocking.ThreadsPerDelayStep_ProcCountFactor` | After the thread count based on `ThreadsToAddWithoutDelay` is reached, this value (after it is multiplied by the processor count) specifies after how many threads an additional `DelayStepMs` would be added to the delay before each new thread is created. | .NET 6 | +| `System.Threading.ThreadPool.Blocking.DelayStepMs` | After the thread count based on `ThreadsToAddWithoutDelay` is reached, this value specifies how much additional delay to add per `ThreadsPerDelayStep` threads, which would be applied before each new thread is created. | .NET 6 | +| `System.Threading.ThreadPool.Blocking.MaxDelayMs` | After the thread count based on `ThreadsToAddWithoutDelay` is reached, this value specifies the max delay to use before each new thread is created. | .NET 6 | +| `System.Threading.ThreadPool.Blocking.IgnoreMemoryUsage` | By default, the rate of thread injection in response to blocking is limited by heuristics that determine whether there is sufficient physical memory available. In some situations, it may be preferable to inject threads more quickly even in low-memory situations. You can disable the memory usage heuristics by turning off this switch. | .NET 7 | + +### How the configuration settings take effect + +- After the thread count based on `MinThreads` is reached, up to `ThreadsToAddWithoutDelay` additional threads may be created without a delay. +- After that, before each additional thread is created, a delay is induced, starting with `DelayStepMs`. +- For every `ThreadsPerDelayStep` threads that are added with a delay, an additional `DelayStepMs` is added to the delay. +- The delay may not exceed `MaxDelayMs`. +- Delays are only induced before creating threads. If threads are already available, they would be released without delay to compensate for blocking work items. +- Physical memory usage and limits are also used and, beyond a threshold, the system switches to slower thread injection. + +### Examples + +*runtimeconfig.json* file: + +```json +{ + "runtimeOptions": { + "configProperties": { + "System.Threading.ThreadPool.Blocking.ThreadsToAddWithoutDelay_ProcCountFactor": 5 + } + } +} +``` + +*runtimeconfig.template.json* file: + +```json +{ + "configProperties": { + "System.Threading.ThreadPool.Blocking.ThreadsToAddWithoutDelay_ProcCountFactor": 5 + } +} +``` + +## `AutoreleasePool` for managed threads + +This option configures whether each managed thread receives an implicit [NSAutoreleasePool](https://developer.apple.com/documentation/foundation/nsautoreleasepool) when running on a supported macOS platform. + +| | Setting name | Values | Version introduced | +| - | - | - | - | +| **runtimeconfig.json** | `System.Threading.Thread.EnableAutoreleasePool` | `true` or `false` | .NET 6 | +| **MSBuild property** | `AutoreleasePoolSupport` | `true` or `false` | .NET 6 | +| **Environment variable** | N/A | N/A | N/A | + +### Examples + +*runtimeconfig.json* file: + +```json +{ + "runtimeOptions": { + "configProperties": { + "System.Threading.Thread.EnableAutoreleasePool": true + } + } +} +``` + +*runtimeconfig.template.json* file: + +```json +{ + "configProperties": { + "System.Threading.Thread.EnableAutoreleasePool": true + } +} +``` + +Project file: + +```xml + + + + true + + + +``` + ## Default stack size for new threads - Specifies the stack size (in bytes) for new VM threads that are created with the default stack size. From b676e5829d26ec9068c9771e68785604425129b3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 7 Nov 2025 18:04:28 +0000 Subject: [PATCH 06/11] Improve examples with platform-specific commands Co-authored-by: agocke <515774+agocke@users.noreply.github.com> --- docs/core/runtime-config/threading.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/core/runtime-config/threading.md b/docs/core/runtime-config/threading.md index b4e18dda2f539..1cd4f63543ece 100644 --- a/docs/core/runtime-config/threading.md +++ b/docs/core/runtime-config/threading.md @@ -281,10 +281,20 @@ Project file: Set the stack size to 2 MB for all new threads: -#### On Windows, Linux, or macOS: - ```shell +# Windows +set DOTNET_Thread_DefaultStackSize=2097152 + +# PowerShell +$env:DOTNET_Thread_DefaultStackSize="2097152" + +# Unix export DOTNET_Thread_DefaultStackSize=2097152 +``` + +Then run your application: + +```shell dotnet myapp.dll ``` From e6af8edf5fce677d0d0489a9b2ec39127ca9a201 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 7 Nov 2025 19:59:33 +0000 Subject: [PATCH 07/11] Match section format with other threading config sections Co-authored-by: agocke <515774+agocke@users.noreply.github.com> --- docs/core/runtime-config/threading.md | 41 +++++---------------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/docs/core/runtime-config/threading.md b/docs/core/runtime-config/threading.md index 1cd4f63543ece..0c163775ded61 100644 --- a/docs/core/runtime-config/threading.md +++ b/docs/core/runtime-config/threading.md @@ -269,41 +269,14 @@ Project file: ## Default stack size for new threads -- Specifies the stack size (in bytes) for new VM threads that are created with the default stack size. -- This setting allows configuration of the stack size for threads created by and other APIs that do not manually specify a stack size. -- If not set, the stack size is determined by the system or runtime default. +- Configures the default stack size (in bytes) for threads created by and other APIs that don't specify an explicit stack size. +- If not specified, the default stack size is determined by the operating system. | | Setting name | Values | Version introduced | | - | - | - | - | -| **Environment variable** | `DOTNET_Thread_DefaultStackSize` | An integer value (bytes). Example: `1048576` for 1 MB | .NET 9 | +| **runtimeconfig.json** | N/A | N/A | N/A | +| **MSBuild property** | N/A | N/A | N/A | +| **Environment variable** | `DOTNET_Thread_DefaultStackSize` | An integer value representing stack size in bytes | .NET 9 | -### Examples - -Set the stack size to 2 MB for all new threads: - -```shell -# Windows -set DOTNET_Thread_DefaultStackSize=2097152 - -# PowerShell -$env:DOTNET_Thread_DefaultStackSize="2097152" - -# Unix -export DOTNET_Thread_DefaultStackSize=2097152 -``` - -Then run your application: - -```shell -dotnet myapp.dll -``` - -#### In C# code (for reference, no runtimeconfig property): - -```csharp -// Stack size is determined by the DOTNET_Thread_DefaultStackSize environment variable -var thread = new Thread(() => { /* thread logic */ }); -thread.Start(); -``` - -**Note:** This setting does not affect threads for which a non-default stack size is specified at creation. +> [!NOTE] +> This setting does not affect threads created with an explicitly specified stack size. From a888838ceb5643819f7c9f0289cbfd444df94613 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 7 Nov 2025 20:05:00 +0000 Subject: [PATCH 08/11] Clarify hex format and main thread behavior Co-authored-by: agocke <515774+agocke@users.noreply.github.com> --- docs/core/runtime-config/threading.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/core/runtime-config/threading.md b/docs/core/runtime-config/threading.md index 0c163775ded61..3b11705d68230 100644 --- a/docs/core/runtime-config/threading.md +++ b/docs/core/runtime-config/threading.md @@ -269,14 +269,14 @@ Project file: ## Default stack size for new threads -- Configures the default stack size (in bytes) for threads created by and other APIs that don't specify an explicit stack size. +- Configures the default stack size (in hexadecimal bytes) for threads created by and other APIs that don't specify an explicit stack size. This setting doesn't affect the main application thread. - If not specified, the default stack size is determined by the operating system. | | Setting name | Values | Version introduced | | - | - | - | - | | **runtimeconfig.json** | N/A | N/A | N/A | | **MSBuild property** | N/A | N/A | N/A | -| **Environment variable** | `DOTNET_Thread_DefaultStackSize` | An integer value representing stack size in bytes | .NET 9 | +| **Environment variable** | `DOTNET_Thread_DefaultStackSize` | An integer value representing stack size in hexadecimal bytes. | .NET 9 | > [!NOTE] -> This setting does not affect threads created with an explicitly specified stack size. +> This setting doesn't affect threads that explicitly specify a stack size at creation. From 9ea89dae8c654ccfd1c2e53efe08be6b7ee0472e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 7 Nov 2025 20:06:36 +0000 Subject: [PATCH 09/11] Clarify hexadecimal format wording Co-authored-by: agocke <515774+agocke@users.noreply.github.com> --- docs/core/runtime-config/threading.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/core/runtime-config/threading.md b/docs/core/runtime-config/threading.md index 3b11705d68230..d08ef9b1f9f8f 100644 --- a/docs/core/runtime-config/threading.md +++ b/docs/core/runtime-config/threading.md @@ -269,14 +269,14 @@ Project file: ## Default stack size for new threads -- Configures the default stack size (in hexadecimal bytes) for threads created by and other APIs that don't specify an explicit stack size. This setting doesn't affect the main application thread. +- Configures the default stack size for threads created by and other APIs that don't specify an explicit stack size. The value is specified as a hexadecimal number representing bytes. This setting doesn't affect the main application thread. - If not specified, the default stack size is determined by the operating system. | | Setting name | Values | Version introduced | | - | - | - | - | | **runtimeconfig.json** | N/A | N/A | N/A | | **MSBuild property** | N/A | N/A | N/A | -| **Environment variable** | `DOTNET_Thread_DefaultStackSize` | An integer value representing stack size in hexadecimal bytes. | .NET 9 | +| **Environment variable** | `DOTNET_Thread_DefaultStackSize` | A hexadecimal integer value representing stack size in bytes. | .NET 9 | > [!NOTE] > This setting doesn't affect threads that explicitly specify a stack size at creation. From 0ec2054e5450f2503b36f7255e933babe7ba8408 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 7 Nov 2025 20:13:34 +0000 Subject: [PATCH 10/11] Add runtimeconfig.json property and examples Co-authored-by: agocke <515774+agocke@users.noreply.github.com> --- docs/core/runtime-config/threading.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/core/runtime-config/threading.md b/docs/core/runtime-config/threading.md index d08ef9b1f9f8f..a906dff27e05f 100644 --- a/docs/core/runtime-config/threading.md +++ b/docs/core/runtime-config/threading.md @@ -274,9 +274,33 @@ Project file: | | Setting name | Values | Version introduced | | - | - | - | - | -| **runtimeconfig.json** | N/A | N/A | N/A | +| **runtimeconfig.json** | `System.Threading.DefaultStackSize` | A hexadecimal integer value representing stack size in bytes. | .NET 9 | | **MSBuild property** | N/A | N/A | N/A | | **Environment variable** | `DOTNET_Thread_DefaultStackSize` | A hexadecimal integer value representing stack size in bytes. | .NET 9 | +### Examples + +*runtimeconfig.json* file: + +```json +{ + "runtimeOptions": { + "configProperties": { + "System.Threading.DefaultStackSize": "0x100000" + } + } +} +``` + +*runtimeconfig.template.json* file: + +```json +{ + "configProperties": { + "System.Threading.DefaultStackSize": "0x100000" + } +} +``` + > [!NOTE] > This setting doesn't affect threads that explicitly specify a stack size at creation. From 489248444af5226e8f8beb521f9a1ac1508edaf6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 7 Nov 2025 20:23:10 +0000 Subject: [PATCH 11/11] Update version to .NET 10 Co-authored-by: agocke <515774+agocke@users.noreply.github.com> --- docs/core/runtime-config/threading.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/core/runtime-config/threading.md b/docs/core/runtime-config/threading.md index a906dff27e05f..0eccd8c7ad5fb 100644 --- a/docs/core/runtime-config/threading.md +++ b/docs/core/runtime-config/threading.md @@ -274,9 +274,9 @@ Project file: | | Setting name | Values | Version introduced | | - | - | - | - | -| **runtimeconfig.json** | `System.Threading.DefaultStackSize` | A hexadecimal integer value representing stack size in bytes. | .NET 9 | +| **runtimeconfig.json** | `System.Threading.DefaultStackSize` | A hexadecimal integer value representing stack size in bytes. | .NET 10 | | **MSBuild property** | N/A | N/A | N/A | -| **Environment variable** | `DOTNET_Thread_DefaultStackSize` | A hexadecimal integer value representing stack size in bytes. | .NET 9 | +| **Environment variable** | `DOTNET_Thread_DefaultStackSize` | A hexadecimal integer value representing stack size in bytes. | .NET 10 | ### Examples