lock
A rule that lets only one thread at a time run a piece of code.
The lock statement acquires exclusive access to a lock object (System.Threading.Lock since .NET 9, or Monitor on any reference type) for the duration of its block.
Loading interactive…
Examples
lock (_gate) { _balance += amount; }lets one thread at a time change the balance.
See also