What is TMonitor in Delphi System unit good for?

自闭症网瘾萝莉.ら 提交于 2019-11-29 22:13:12

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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!