Наткнулся тут на чудный кусок в System.pas:
{ TMonitor is an implementation of the concept invented by C.A.R Hoare and Per Brinch Hansen.
See http://en.wikipedia.org/wiki/Monitor_%28synchronization%29 for more information.
Every TObject derived instance can be used as a monitor. However, it is recommended that privately
constructed objects be used rather than the publicly available instance itself. This will allow the
developer to better control access to the lock and to ensure that the locking rules are adhered to.
If a publicly available instance were to be used a the lock, such as a TComponent derivative, then
deadlocks are more likely when external code is locking and unlocking the monitor in addition to
the code internal to the class. In many cases, a mutex/critical section/condition variable can be
created by simply constructing a variable of type TObject and calling the TMonitor.XXXX(ObjInstance)
methods. }
PPMonitor = ^PMonitor;
PMonitor = ^TMonitor;
TMonitor = record
{ TMonitor is an implementation of the concept invented by C.A.R Hoare and Per Brinch Hansen.
See http://en.wikipedia.org/wiki/Monitor_%28synchronization%29 for more information.
Every TObject derived instance can be used as a monitor. However, it is recommended that privately
constructed objects be used rather than the publicly available instance itself. This will allow the
developer to better control access to the lock and to ensure that the locking rules are adhered to.
If a publicly available instance were to be used a the lock, such as a TComponent derivative, then
deadlocks are more likely when external code is locking and unlocking the monitor in addition to
the code internal to the class. In many cases, a mutex/critical section/condition variable can be
created by simply constructing a variable of type TObject and calling the TMonitor.XXXX(ObjInstance)
methods. }
PPMonitor = ^PMonitor;
PMonitor = ^TMonitor;
TMonitor = record
То есть получается, что любой объект Delphi может служить объектом синхронизации. Примерно как у Apple - synchronize(self).
http://docwiki.embarcadero.com/Libraries/Seattle/en/System.TMonitor
Правда из-за этого теперь ВСЕ объекты стали на SizeOf(Pointer) БОЛЬШЕ :-(
hfFieldSize = SizeOf(Pointer);
hfMonitorOffset = 0;
(+) Важно.
https://www.delphitools.info/2013/06/06/tmonitor-vs-trtlcriticalsection/
https://www.delphitools.info/2013/05/30/performance-issue-in-nextgen-arc-model/#more-2486
Т.е. любой объект можно использовать как критическую секцию:
System.TMonitor.Enter(Self); try // - защищаемый код finally System.TMonitor.Exit(Self); end
Или как Event:
System.TMonitor.PulseAll(Self); ... System.TMonitor.Wait(Self);
http://docwiki.embarcadero.com/Libraries/Seattle/en/System.TMonitor
Правда из-за этого теперь ВСЕ объекты стали на SizeOf(Pointer) БОЛЬШЕ :-(
hfFieldSize = SizeOf(Pointer);
hfMonitorOffset = 0;
class function TMonitor.GetFieldAddress(const AObject: TObject): PPMonitor;
begin
Result := PPMonitor(PByte(AObject) + AObject.InstanceSize - hfFieldSize + hfMonitorOffset);
end;
https://www.delphitools.info/2013/06/06/tmonitor-vs-trtlcriticalsection/
https://www.delphitools.info/2013/05/30/performance-issue-in-nextgen-arc-model/#more-2486
Не перестает мне нравиться твоя манера снобистски всех вокруг поучать при том, что о новинках Delphi 2009 ты впервые слышишь в 2017 году.
ОтветитьУдалитьНе перестает мне нравится твоя манера анонимно тыкать незнакомым людям.
Удалить