[erlang-questions] compare and set semantics using ets?

Anton Lebedevich <>
Tue Jan 15 10:41:37 CET 2013


On 01/14/2013 07:13 PM, Anton Lebedevich wrote:
> On 01/14/2013 07:01 PM, Jesper Louis Andersen wrote:
>> On Jan 14, 2013, at 1:08 PM, Anton Lebedevich <> wrote:
>>
>>> Is it possible to implement atomic compare-and-set semantics using ets?
>>
>> Only in a limited fashion. I guess we either need a specific CAS-instruction, or you have to look up how it is achieved in mnesia, which does to transactional updates.
> 
> Good catch, I've completely forgot that mnesia already does it, will
> take a look at its sources.

Reading mnesia sources revealed that it uses transaction manager and
locker processes to serialize modification operations.
Mnesia transactions rely on making modifications sequential not on
CAS-instructions.

It turns out that CAS which is a workhorse of many non-Erlang concurrent
libraries isn't available in Erlang without NIFs. Am I missing something?

Regards,
Anton Lebedevich.



More information about the erlang-questions mailing list