Re: [Pharo-dev] Lock-free Atomic Counter ?

2014-04-04 Thread Sven Van Caekenberghe
Just for the sake of discussion, you try to prevent interruptions by using assignments, right ? But you still need #== which seems like a (potential) message send, which brings us back to the other arguments in this thread. Furthermore, the dummy value must be different for each of the

Re: [Pharo-dev] Lock-free Atomic Counter ?

2014-04-04 Thread Sven Van Caekenberghe
On 04 Apr 2014, at 19:29, Igor Stasenko siguc...@gmail.com wrote: On 4 April 2014 18:31, Sven Van Caekenberghe s...@stfx.eu wrote: Just for the sake of discussion, you try to prevent interruptions by using assignments, right ? But you still need #== which seems like a (potential) message

Re: [Pharo-dev] Lock-free Atomic Counter ?

2014-04-04 Thread Igor Stasenko
On 4 April 2014 22:54, Sven Van Caekenberghe s...@stfx.eu wrote: On 04 Apr 2014, at 19:29, Igor Stasenko siguc...@gmail.com wrote: On 4 April 2014 18:31, Sven Van Caekenberghe s...@stfx.eu wrote: Just for the sake of discussion, you try to prevent interruptions by using assignments, right

Re: [Pharo-dev] Lock-free Atomic Counter ?

2014-04-03 Thread Levente Uzonyi
On Thu, 3 Apr 2014, Igor Stasenko wrote: On 3 April 2014 00:11, Sven Van Caekenberghe s...@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

Re: [Pharo-dev] Lock-free Atomic Counter ?

2014-04-03 Thread Benjamin Pollack
I hate to bust this old evilness out, but is it feasible to abuse #become: for this purpose? I haven't used it in so long I don't actually remember whether that's feasible semantics with ivars. On Thu, Apr 3, 2014, at 09:08 AM, Levente Uzonyi wrote: On Thu, 3 Apr 2014, Igor Stasenko wrote:

[Pharo-dev] Lock-free Atomic Counter ?

2014-04-02 Thread Sven Van Caekenberghe
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 ? I vaguely remember a discussion about that long ago... TIA, Sven

Re: [Pharo-dev] Lock-free Atomic Counter ?

2014-04-02 Thread Igor Stasenko
On 3 April 2014 00:11, Sven Van Caekenberghe s...@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

Re: [Pharo-dev] Lock-free Atomic Counter ?

2014-04-02 Thread Igor Stasenko
so, lock-free counter can be something like: atomicIncr | oldValue | [ oldValue := self atomicSwapCounterWithDummy. oldValue == dummy ] whileTrue: [ Processor yield ]. ^ counter := oldValue + 1 atomicSwapCounterWithDummy | old | old := counter. counter := dummy. ^ old so you use dummy to

Re: [Pharo-dev] Lock-free Atomic Counter ?

2014-04-02 Thread Igor Stasenko
extra note about yielding: - if i remember correctly, it yields on same priority level, letting other process (if any) at same priority level to take control. and if there's none, then it is NOP. so, if counter incr. used by processes with different priority it is better to replace it with 1 ms