[erlang-questions] atomic ETS update with a function?

Vans S vans_163@REDACTED
Tue Nov 20 20:18:07 CET 2018


 Interesting use for select_replace, I think I see. If Old changes in the meantime, it wont succeed as Old wont be found.

I am aware of select_replace, did not realise you could use it this way. Nifty!
    On Tuesday, November 20, 2018, 9:16:04 a.m. EST, Sverker Eriksson <sverker@REDACTED> wrote:  
 
 
You can use ets:select_replace/2 to do an atomic compare-and-swap operation:



 [Old] = ets:lookup(T, Key),New = update_object(Old),Success = (1 =:= ets:select_replace(T, [{Old, [], [{const, New}]}])),


ets:select_replace/2 was introduced in OTP-20.

/Sverker	
On mån, 2018-11-19 at 18:44 +0000, Vans S wrote:
Currently there is no atomic function to update a ETS value when its not a tuple.  For example if one of my ETS values is a map, and I want to put an element into the map, I have no atomic way to do so.

Is there anyone else that really has a need for a function like :ets.update/3 where arg 1 is ets_table, 2 is key, 3 is fun callback that is called passing the original element and the reply should be the new element?_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED
http://erlang.org/mailman/listinfo/erlang-questions
  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20181120/58afd161/attachment.htm>


More information about the erlang-questions mailing list