The NonReentrantLock provides a lightweight mutual exclusion class that doesn't use Windows kernel synchronization primitives.
The implementation is distilled from the workings of T:System.Threading.SemaphoreSlim The basic idea is that we use a regular sync object (Monitor.Enter/Exit) to guard the setting of an 'owning thread' field. If, during the Wait, we find the lock is held by someone else then we register a cancellation callback and enter a "Monitor.Wait" loop. If the cancellation callback fires, then it "pulses" all the waiters to wake them up and check for cancellation. Waiters are also "pulsed" when leaving the lock.
All public members of NonReentrantLock are thread-safe and may be used concurrently from multiple threads.