Atomicity of Cells
Raphael Collet
raph at info.ucl.ac.be
Mon Jan 17 15:05:24 CET 2005
Dear Christopher,
> Exchange is atomic on cells, what about '@' and Cell.access? I am
If C is a cell, then X=@C is the same as X={Access C}, which is the same
as {Exchange C X X}. There is only *one* stateful operation, so it is
atomic by definition.
> writing some code that processes one task at a time incoming on a stream
> that must shutdown on after completing one task but before beginning
> another. The task execution unit is only given a future to the stream.
> My initial thought was to use a lock guarding the cell, but I was
> wondering if atomicity is guaranteed for reading of cells as in the
> following.
What you mean is not clear to me. Can you tell exactly which sequence
of operations you want to be performed atomically?
What is clear in your example is that ToShutdown can be assigned to true
while you're in the inner try/catch statement. So if you have another
expression "@ToShutdown" in the 'for' loop, you might get a different
value than the one in the 'if' statement.
> proc {NewTaskUnit Log Name TaskStream ?TU}
>
> ToShutdown
>
> proc {Shutdown}
> {Exchange ToShutdown _ true}
> end
> in
> {NewCell false ToShutdown}
> thread
> try
> for T in TaskStream do
> if @ToShutdown == false then
> try
> {Log log(message: "Agent <"#Name#">: Beginning Task...")}
> {DoTask T}
> {Log log(message: "Agent <"#Name#">: Task completed.")}
> catch unknownTask then
> {Log log(message: "Agent <"#Name#">: Unknown task type")}
> [] E then
> {Log log(message: "Agent <"#Name#">: Unknown error...\n\n"#E)}
> end
> else
> raise exitLoopNow end
> end
> end
> catch
> endLoopNow then
> skip % exit loop.
> [] E then
> skip % what now?
> end
> end
>
> TU = taskUnit(shutdown: Shutdown)
> end
Hope this helps.
Cheers,
raph
More information about the mozart-users
mailing list