Ensure consistency between ThreadState.Stopped APIs that check if a thread is dead#122568
Merged
jkoritzinsky merged 4 commits intodotnet:mainfrom Dec 15, 2025
Merged
Ensure consistency between ThreadState.Stopped APIs that check if a thread is dead#122568jkoritzinsky merged 4 commits intodotnet:mainfrom
jkoritzinsky merged 4 commits intodotnet:mainfrom
Conversation
…hread is dead. When a managed thread dies, set _isDead, and make _isDead short-circuit thread state fetching
Contributor
|
Tagging subscribers to this area: @mangod9 |
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request improves consistency in how thread death is reported by consolidating the mechanism to use the _isDead field instead of the TS_ReportDead thread state flag. The change simplifies the threading model by having the managed code directly check _isDead before querying the native thread state, rather than relying on a QCall to set TS_ReportDead.
- Removes the
ThreadNative_ReportDeadQCall and its infrastructure - Updates
ThreadNative_GetThreadStateto include other thread state flags even when the thread is dead (aligning with debugger interface behavior) - Makes the
ThreadStateproperty short-circuit to returnThreadState.Stoppedwhen_isDeadis true, avoiding unnecessary native calls
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/coreclr/vm/qcallentrypoints.cpp | Removes the ThreadNative_ReportDead QCall entry point |
| src/coreclr/vm/comsynchronizable.h | Removes the ThreadNative_ReportDead function declaration |
| src/coreclr/vm/comsynchronizable.cpp | Removes the ThreadNative_ReportDead function implementation and updates ThreadNative_GetThreadState to OR the ThreadStopped flag instead of early-returning when a thread is dead |
| src/coreclr/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs | Adds early return in ThreadState property when _isDead is true; removes ReportDead P/Invoke and NotifyThreadDeath method; sets _isDead = true at the start of OnThreadExiting |
src/coreclr/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs
Outdated
Show resolved
Hide resolved
….CoreCLR.cs Co-authored-by: Copilot <[email protected]>
jkotas
reviewed
Dec 15, 2025
src/coreclr/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs
Show resolved
Hide resolved
jkotas
approved these changes
Dec 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a managed thread dies, set _isDead, and make _isDead short-circuit thread state fetching instead of setting the ReportDead state before we do unmanaged thread cleanup.
Fixes #122520