Replace object locks with System.Threading.Lock#1977
Merged
Conversation
58ebd6f to
f6a7199
Compare
.NET 9+ introduced System.Threading.Lock as a dedicated, lightweight synchronization primitive. Migrate all private lock fields from `object` + `new object()` to `Lock` + `new Lock()`. Also replace Monitor.IsEntered() assertions in GitStatusCache with Lock.IsHeldByCurrentThread, since Lock is not compatible with Monitor APIs. 20 fields across 19 files updated. No Monitor.Wait/Pulse usage found in the codebase, so all instances are safe to migrate. Assisted-by: Claude Opus 4.6 Signed-off-by: Tyrie Vella <tyrielv@gmail.com>
f6a7199 to
5eeba9e
Compare
KeithIsSleeping
approved these changes
May 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrate all private lock fields from
object+new object()toSystem.Threading.Lock+new Lock(), the dedicated lightweight synchronization primitive introduced in .NET 9.Changes
private [static] [readonly] object fooLock = new object()→Lock fooLock = new Lock()GitStatusCache.csreplaced withLock.IsHeldByCurrentThread(Monitor APIs are incompatible with the Lock type)using System.Threading;to 10 files that were missing itWhy
System.Threading.Lockis purpose-built forlock()usage — it avoids the overhead of locking on a general-purposeobjectand makes the intent explicit. Since VFSForGit now targets .NET 10, all lock fields can benefit from this.No instances of
Monitor.Wait/Pulse/Enter/Exitwere found, so every lock object in the codebase was a straightforward migration candidate.Validation