Dear Kevin,
On 24.05.2006, at 22:41, Kevin Glynn wrote:
Torsten Anders writes:
On 24.05.2006, at 20:04, Himanshu Neema wrote
Let me know if it can be still improved/corrected.
You may consider making the OrderedDictionary thread-save using a
lock.
It should be possible to avoid using locks, e.g. my version used
Dictionary.condExchange to make the put routine thread-safe.
Could you please explain why your version (see below your definition of
Put) is thread-save? You have two stateful operations (one on the
dictionary one on the counter cell) which are not atomic. Would it not
be possible to access the OrderedDictionary in a non-consistent state
between these two operations?
proc {Put D Key Item}
NewSeq
_#OldSeq = {Dictionary.condExchange D Key _#unit $ Item#NewSeq}
in
if OldSeq == unit then NewCounter in
%% Key is new
{Cell.exchange Counter NewSeq NewCounter} %% or, NewSeq =
Counter := NewCounter
NewCounter = NewSeq + 1
else
NewSeq = OldSeq
end
end
Thank you!
Best,
Torsten
--
Torsten Anders
Sonic Arts Research Centre • Queen's University Belfast
Frankstr. 49 • D-50996 Köln
Tel: +49-221-3980750
www.torsten-anders.de
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users