Repository navigation
Add FEATURE_MULTITHREADING ifdefs to a couple places in CoreLib - #137076
Conversation
Exclude constructor locks and cross-thread deadlock tracking when FEATURE_MULTITHREADING is disabled, while preserving recursion and cached failures. Remove the obsolete WASM initialization fallback in favor of startup initialization. Local size-optimized, invariant WASI Hello World: 838510 -> 834900 bytes (-3610 bytes). Co-authored-by: Copilot <[email protected]> Copilot-Session: 9bc3dfee-1040-4648-bdad-86922a749613
Use a fixed executing-thread ID without TLS, ID-dispenser allocation, or finalization when FEATURE_MULTITHREADING is disabled. Preserve distinct IDs for unstarted Thread objects with a checked counter. Co-authored-by: Copilot <[email protected]> Copilot-Session: 9bc3dfee-1040-4648-bdad-86922a749613
Compile foreground accounting, shutdown waits, exit callbacks, and private Thread locking only with FEATURE_MULTITHREADING. Preserve thread properties, validation, and the background state observed by ProcessExit handlers. Validated WASI Release/Checked shutdown and priority probes plus Preinitialization, and compiled Windows x64 Debug CoreLib. WASI Release Hello World shrinks from 832265 to 825570 bytes. Co-authored-by: Copilot <[email protected]> Copilot-Session: 9bc3dfee-1040-4648-bdad-86922a749613
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
That's why |
rt-sz takes shortcuts and uses daily builds of the .NET SDK with overriden IlcToolsPath etc. It would have to be rewritten to work different and likely build more of the repo. It already takes half an hour to get results and that feels like too much already. |
jkoritzinsky
left a comment
There was a problem hiding this comment.
Jan's already commented on my concerns. LGTM otherwise
Split ManagedThreadId into conditionally included multithreading and single-threading files in NativeAOT and CoreCLR. Move NativeAOT thread lifecycle members into the multithreading partial and remove threading feature guards from Windows-specific code. Validated Windows Debug and WASI Checked CoreCLR/NativeAOT CoreLib builds, Windows NativeAOT smoke tests, and WASI identity and normal/explicit shutdown probes. CoreCLR execution was not tested. Co-authored-by: Copilot <[email protected]> Copilot-Session: d2be6eb7-4bbd-4c48-9031-40db58562aeb
Move the managed thread ID field and accessor back below s_idDispenser to avoid an unrelated diff against main. Declaration placement only; no behavior change. Co-authored-by: Copilot <[email protected]> Copilot-Session: d2be6eb7-4bbd-4c48-9031-40db58562aeb
There was a problem hiding this comment.
🟡 Changes recommended
The new single-threaded NativeAOT ID allocator lacks coverage verifying that unstarted threads receive distinct IDs greater than 1 before first current-thread access, while both current-thread ID APIs remain 1.
1 open issue
What changed in this PR
This PR reduces code included in single-threaded CoreLib builds by separating thread-specific implementations and excluding multithreading infrastructure.
Changes:
- Split managed thread ID implementations by threading configuration in CoreCLR and NativeAOT.
- Move NativeAOT thread lifecycle bookkeeping and synchronization into the multithreaded implementation.
- Exclude class-constructor locks and deadlock tracking from single-threaded builds.
Builds and tests were not run.
| File | Description |
|---|---|
| src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj | Selects the appropriate managed thread ID implementation. |
| src/coreclr/System.Private.CoreLib/src/System/Threading/ManagedThreadId.CoreCLR.SingleThreading.cs | Provides constant current-thread IDs for single-threaded CoreCLR. |
| src/coreclr/System.Private.CoreLib/src/System/Threading/ManagedThreadId.CoreCLR.Multithreading.cs | Retains the thread-local CoreCLR implementation. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.Windows.cs | Removes conditional guards around Windows thread creation. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.Unix.SingleThreading.cs | Removes the single-threaded Unix thread-exit callback. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.SingleThreading.cs | Preserves background-state handling during shutdown. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.Multithreading.cs | Houses thread locks, exit registration, and foreground-thread bookkeeping. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.cs | Gates shared thread operations on multithreading support. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/ManagedThreadId.SingleThreading.cs | Adds a simple allocator for unstarted-thread IDs. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/ManagedThreadId.Multithreading.cs | Preserves the existing thread ID allocation and recycling implementation. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/ClassConstructorRunner.cs | Conditionally excludes synchronization and removes the WebAssembly initialization fallback. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj | Selects the NativeAOT thread ID implementation by configuration. |
Review effort: Balanced
GHA job timeout is 6h, so it's well within the range. We are doing full VMR linux-riscv64 build (which uses --bootstrap at runtime stage) and the whole job takes about 80-90 mins (https://github.com/filipnavara/dotnet-riscv/actions/workflows/build.yml). For rt-sz, it could be used sparingly only for the targets without the runtime packs. |
Co-authored-by: Copilot <[email protected]> Copilot-Session: 19e58cf4-88eb-4756-b88d-de581568086a
Restore the existing Lock-based class constructor runner on single-threaded targets instead of conditionally compiling out its locks. Leave the managed thread ID and thread lifecycle specializations unchanged. Addresses dotnet#137076 (comment). Co-authored-by: Copilot <[email protected]> Copilot-Session: a4983540-34d2-4b99-8e53-4b7796fc9228
Correct the overly broad class constructor rollback: keep DeadlockAwareAcquire, BlockingRecord, and Cctor.Count conditional on FEATURE_MULTITHREADING, and keep the obsolete WASM lazy initialization removed. Retain unconditional Lock usage, using a recursion check and TryEnter for single-threaded class constructor acquisition. Co-authored-by: Copilot <[email protected]> Copilot-Session: a4983540-34d2-4b99-8e53-4b7796fc9228
jkotas
left a comment
There was a problem hiding this comment.
The last iteration looks reasonable to me
|
/ba-g osx leg got stuck and timed out |

Each of these is a small saving. Cannot run rt-sz on this because we still don't have runtime packs.