Skip to content

Commit cef5dea

Browse files
authored
Fix to allow entering cooperative GC mode when the thread is in a forbid-suspend-for-debugger region (#42587)
- Followup to #40060 - In short timing windows if a thread is placed in a pending-suspend-for-debugger state while in a forbid-suspend-for-debugger region, from the above PR it would not suspend for the debugger but it was missed that it can also get stuck in a perpetual spin-wait while entering cooperative GC mode. This causes the thread to not suspend for the debugger (VS times out after waiting) and the thread can only progress by unmarking it for debugger suspension. - Fixed to break the spin-wait by checking whether the thread is in the forbid region Fix for #42375 in master
1 parent 3492460 commit cef5dea

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/coreclr/src/vm/threadsuspend.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,8 +2269,9 @@ void Thread::RareDisablePreemptiveGC()
22692269
// Note IsGCInProgress is also true for say Pause (anywhere SuspendEE happens) and GCThread is the
22702270
// thread that did the Pause. While in Pause if another thread attempts Rev/Pinvoke it should get inside the following and
22712271
// block until resume
2272-
if ((GCHeapUtilities::IsGCInProgress() && (this != ThreadSuspend::GetSuspensionThread())) ||
2273-
(m_State & (TS_DebugSuspendPending | TS_StackCrawlNeeded)))
2272+
if ((GCHeapUtilities::IsGCInProgress() && (this != ThreadSuspend::GetSuspensionThread())) ||
2273+
((m_State & TS_DebugSuspendPending) && !IsInForbidSuspendForDebuggerRegion()) ||
2274+
(m_State & TS_StackCrawlNeeded))
22742275
{
22752276
STRESS_LOG1(LF_SYNC, LL_INFO1000, "RareDisablePreemptiveGC: entering. Thread state = %x\n", m_State.Load());
22762277

@@ -2361,7 +2362,8 @@ void Thread::RareDisablePreemptiveGC()
23612362
// thread while in this loop. This happens if you use the COM+
23622363
// debugger to suspend this thread and then release it.
23632364
if (! ((GCHeapUtilities::IsGCInProgress() && (this != ThreadSuspend::GetSuspensionThread())) ||
2364-
(m_State & (TS_DebugSuspendPending | TS_StackCrawlNeeded))) )
2365+
((m_State & TS_DebugSuspendPending) && !IsInForbidSuspendForDebuggerRegion()) ||
2366+
(m_State & TS_StackCrawlNeeded)) )
23652367
{
23662368
break;
23672369
}

0 commit comments

Comments
 (0)