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 block anyone from setting the new value unless you set it.
dummy can be any object (not a number in your care),
and lastly, once you assign a new value, you effectively release a "lock"
:)
Processor yield is mainly attempt to avoid busy-waiting.