[Pharo-dev] Lock-free Atomic Counter ?

Igor Stasenko siguctua at gmail.com
Wed Apr 2 19:28:21 EDT 2014

On 3 April 2014 00:11, Sven Van Caekenberghe <sven at stfx.eu> wrote:

> Hi,
> Is it possible to have a simple lock-free atomic counter in Pharo 3.0 ?
> nextId
>   ^ idCounter := idCounter + 1
> Or is it still possible that two process entering this code can mess
> things up ?
> #+ is a message send. So technically, if you will be interrupted at the
point of
returning a result from it, then somebody else could run #nextId without
as result you will get 2 processes returning same value from #nextId.
(and increasing numbers of concurrent processes will produce even more
surprising results :)

> I vaguely remember a discussion about that long ago...
> assignment is atomic.. the one which i use in atomic queue impl., but it
is hidden, undocumented VM implementation detail :) e.g.:

oldA := a.
a := newA.
actually can be any series of it, as long as nothing else there (no message

x:= a.
z := c.
w := e.

will be performed atomically.

> TIA,
> Sven

Best regards,
Igor Stasenko.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20140403/2167b953/attachment-0002.html>

More information about the Pharo-dev mailing list