TMonitor combines the notion of a critical section (or a simple mutex) along with a condition variable. You can read about what a “monitor” is here:
http://en.wikipedia.org/wiki/Monitor_%28synchronization%29
Any place you would use a critical section, you can use a monitor. Instead of declaring a TCriticalSection
, you can simple create a TObject
instance and then use that:
TMonitor.Enter(FLock);
try
// protected code
finally
TMonitor.Exit(FLock);
end;
Where FLock
is any object instance. Normally, I just create a TObject
:
FLock := TObject.Create;