Skip to content

Commit fa52f3a

Browse files
kouvelRuihan-Yin
authored andcommitted
Notify the debugger of a cross-thread dependency in Lock (dotnet#101501)
* Notify the debugger of a cross-thread dependency in Lock When a FuncEval tries to acquire a Lock that is held by a different thread, notify the debugger of a cross-thread dependency.
1 parent 3b12766 commit fa52f3a

File tree

1 file changed

+11
-0
lines changed
  • src/libraries/System.Private.CoreLib/src/System/Threading

1 file changed

+11
-0
lines changed

src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs

+11
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,17 @@ private ThreadId TryEnterSlow(int timeoutMs, ThreadId currentThreadId)
334334
return new ThreadId(0);
335335
}
336336

337+
//
338+
// At this point, a full lock attempt has been made, and it's time to retry or wait for the lock.
339+
//
340+
341+
// Notify the debugger that this thread is about to wait for a lock that is likely held by another thread. The
342+
// debugger may choose to enable other threads to run to help resolve the dependency, or it may choose to abort the
343+
// FuncEval here. The lock state is consistent here for an abort, whereas letting a FuncEval continue to run could
344+
// lead to the FuncEval timing out and potentially aborting at an arbitrary place where the lock state may not be
345+
// consistent.
346+
Debugger.NotifyOfCrossThreadDependency();
347+
337348
if (LazyInitializeOrEnter() == TryLockResult.Locked)
338349
{
339350
goto Locked;

0 commit comments

Comments
 (0)