The Delphi Geek – In response to my recent article on various kinds of initialization, GJ proposed another algorithm, which I will call here busy-wait initialization. This is the first time I’ve encountered this approach and I have no idea whether it is wide-known and has an “official” name. The algorithm itself is very simple: class function BusyWait<T>.Initialize(var storage: T; factory: TFactory): T; begin if storage <> nil then begin if InterlockedCompareExchangePointer( PPointer(@storage)^, PPointer(@factory)^, nil) = nil then storage := factory(); while ...
Visits by Source
Users who voted for this posting