Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify the debugger of a cross-thread dependency in Lock #101501

Merged
merged 2 commits into from
May 2, 2024
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
11 changes: 11 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,17 @@ private ThreadId TryEnterSlow(int timeoutMs, ThreadId currentThreadId)
return new ThreadId(0);
}

//
// At this point, a full lock attempt has been made, and it's time to retry or wait for the lock.
//

// Notify the debugger that this thread is about to wait for a lock that is likely held by another thread. The
// debugger may choose to enable other threads to run to help resolve the dependency, or it may choose to abort the
// FuncEval here. The lock state is consistent here for an abort, whereas letting a FuncEval continue to run could
// lead to the FuncEval timing out and potentially aborting at an arbitrary place where the lock state may not be
// consistent.
Debugger.NotifyOfCrossThreadDependency();

if (LazyInitializeOrEnter() == TryLockResult.Locked)
{
goto Locked;
Expand Down
Loading