Skip to content

Conversation

@jkoritzinsky
Copy link
Member

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

…hread is dead.

When a managed thread dies, set _isDead, and make _isDead short-circuit thread state fetching
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_ReportDead QCall and its infrastructure
  • Updates ThreadNative_GetThreadState to include other thread state flags even when the thread is dead (aligning with debugger interface behavior)
  • Makes the ThreadState property short-circuit to return ThreadState.Stopped when _isDead is 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

….CoreCLR.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jkoritzinsky jkoritzinsky enabled auto-merge (squash) December 15, 2025 22:49
@jkoritzinsky jkoritzinsky merged commit 14a10b6 into dotnet:main Dec 15, 2025
98 checks passed
@jkoritzinsky jkoritzinsky deleted the thread-state-fix branch January 9, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System.Threading.Threads.Tests.ThreadTests.IsBackgroundTest test failure

2 participants