Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/coreclr/vm/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2896,6 +2896,12 @@ void Thread::OnThreadTerminate(BOOL holdingLock)

}

if (m_State & TS_DebugWillSync)
{
ResetThreadState(TS_DebugWillSync);
InterlockedDecrement(&m_DebugWillSyncCount);
Copy link
Preview

Copilot AI Apr 22, 2025

Choose a reason for hiding this comment

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

Consider adding an assertion or check to ensure that m_DebugWillSyncCount is positive before decrementing to avoid potential underflow if multiple thread terminations occur in succession.

Suggested change
InterlockedDecrement(&m_DebugWillSyncCount);
if (m_DebugWillSyncCount > 0)
{
InterlockedDecrement(&m_DebugWillSyncCount);
}

Copilot uses AI. Check for mistakes.

Copy link
Member

Choose a reason for hiding this comment

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

Is this is a regression in 9, seems like it is from the bug?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is this is a regression in 9, seems like it is from the bug?

We believe that the issue has always existed, but something in .NET 9 may have caused it to happen more often. Perhaps it is a timing issue.

}

SetThreadState(TS_Dead);
ThreadStore::s_pThreadStore->m_DeadThreadCount++;
ThreadStore::s_pThreadStore->IncrementDeadThreadCountForGCTrigger();
Expand Down