Atomicity of Cells
Christopher Campbell
campbell at dcs.gla.ac.uk
Mon Jan 17 15:47:29 CET 2005
Raphael Collet wrote:
> 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.
I see. Interesting.
>>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?
I was concerned that reading the cell wasn't guaranteed to be
consistent, however I hadn't considered what that would mean for
updating the cell. That would mean the update operation was not atomic
(you could read an intermediate state), but it is atomic so that can't
happen by definition.
It doesn't matter if the cell changes after a single task has began
executing. It only matters that we stop after we have completed a task,
so that no more tasks are processed.
> 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.
Fortunately this is guaranteed not to happen, it is only checked once to
determine whether or not to continue processing tasks. That is the only
purpose of the ToShutdown cell.
Thanks,
Chris
More information about the mozart-users
mailing list