2
votes
Vote UpVote

On Optimistic and Pessimistic Initialization

The Delphi Geek – When you want to initialize a shared resource in a multithreaded application, you have two possibilities to choose from – optimistic and pessimistic. The difference between them is visible from the pseudocode. var Shared: T;procedure OptimisticInitializer;var temp: T;begin if not assigned(Shared) then begin temp := T.Create; if not AtomicallyTestAndStore(Shared, nil, temp) then temp.Free; end;end;procedure PessimisticInitializer;begin if not assigned(Shared) then begin Lock; try if not assigned(Shared) then Shared := T.Create; finally Unlock; end; end;end; ...
Favorite? Off-Topic? gabr @ 2011-12-02 13:55

Statistics

Visits: 745
Votes: 2
Favorites: 0
Off-Topic: 0

Visits by Source

User Actions

Users who voted for this posting

knight_killer
vcldeveloper
Subscribe:
Contact us to advertise on DelphiFeeds.com

Community Links

Torry Firebird News

Sponsor

 
Please login or register to use this functionality.
(click on this box to dismiss)