2015-10-12 15:33 GMT+02:00 phil@highoctane.be <phil@highoctane.be>:

On Mon, Oct 12, 2015 at 3:20 PM, Thierry Goubier <thierry.goubier@gmail.com> wrote:
Hi Sebasti��n,

2015-10-12 13:53 GMT+02:00 Sebasti��n Krynski <skrynski@gmail.com>:
Hello my name is Sebasti��n Krynski from Buenos Aires, Argentina.
Just writing to let you know that I'm starting to work on adding an atomic swap operator in Pharo , guaranteed not to be interrupted by the VM. The operator will be used this way:

a :=: b

meaning 'swap variable a with variable b'.

Why a cryptic, special syntax? The compiler could inline an explicit message send which would make the intent clear.

See previous discussions about <=> indeed.��

a atomicSwapWith: b.

Well, anyway, the compiler has to do something special there.

Could we have something like...

[ | temp |
�� temp := a.
�� a := b.
�� b := a ] atomic

? Would a compiler be able to merge that in a swap instruction? And make another type of processing for a different code inside the block?

We have Mutex>>critical: aBlock etc.

Why not Atomic>>do: aBlock ?��

Honestly this block followed by atomic is very confusing IMO. That means that the compiler has to raise an error if it did not succeed to compile the block in a single cpu instruction, i.e., a single bytecode that compiles to a single cpu instruction. For example:
[ | temp |
�� temp := a.
�� a := b.
�� b := a.
�� self foo ] atomic
has to raise a compilation error as the block cannot be compiled in a single instruction. Overall very few instructions in specific order can be compiled in a such a block.

Atomic>>#do: can work but the argument block needs to be compiled in a single instruction so the bytecode compiler has to aware of the syntax based on the selector anyway. For example, in:
anAtomic do: [ | temp |
�� temp := a.
�� a := b.
�� b := a ]
then the compiler has to compile the block specifically to have single instruction, even if the call to anAtomic is done in the runtime.

On the other hand a new special selector as #atomicSwapWith:, in a similar way to #ifTrue:ifFalse:, is definitely doable and easy to implement. If you think it's more readable then it's the way to go. It does not extend the syntax so I think it can be done like that for the experiment as it is simpler to implement.��

��

Would indeed be more readable than :=:

Phil
��
In order to do this I will be modifying the VM and the Compiler .

Good luck. This is an important step.
��
I'm working under the direction of INRIA and Gabriela Ar��valo.

Welcome!

Thierry