Lock (Monitor) internal implementation in .NET

The Wikipedia article has a pretty good description of what a “Monitor” is, as well as its underlying technology, the Condition Variable.

Note that the .NET Monitor is a correct implementation of a condition variable; most published Win32 implementations of CVs are incorrect, even ones found in normally reputable sources such as Dr. Dobbs. This is because a CV cannot easily be built from the existing Win32 synchronization primitives.

Instead of just building a shallow (and incorrect) wrapper over the Win32 primitives, the .NET CV implementation takes advantage of the fact that it’s on the .NET platform, implementing its own waiting queues, etc.

Leave a Comment