Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is TMonitor in Delphi System unit good for?

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.

Anyplace 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;