How .NET 9 replaces object monitor locks with dedicated System.Threading.Lock:
Before C# 13, lock(new object()) compiled to Monitor.Enter() / Monitor.Exit(), requiring runtime sync block index allocations in the object header.
In .NET 9:
private readonly Lock _gate = new();
void ThreadSafeOperation()
{
lock (_gate) // C# 13 emits _gate.EnterScope()!
{
// Critical Section
}
}Lock.EnterScope() returns a ref struct scope guard. Eliminates sync block table lookups and executes faster on multi-core CPUs!