[erlang-questions] atomic ets:take_first, ets:take_last

Mikael Pettersson mikpelinux@REDACTED
Sat Jul 16 16:36:42 CEST 2016


Alexandre Beniaminov writes:
 > Thank you.
 > You're right, and you've answered on part of my question:
 > 
 > << Now, anything can happen in between, so in particular, ets:take/2 may
 > return [] if the key was deleted or taken out by another process between
 > the two calls.>>
 > 
 > I would like to ask the community what do you think about to add  to ets
 > module two atomic functions: ets:take_first/1 and ets:take_last/1  ?

I would be more interested in a generalized atomic compare_and_<op> function,
where <op> could be to delete the record or to update one of its fields.

take_first could then be synthesized on top of first + compare_and_delete.

My interest here is in building synchronisation objects without having to
call a helper process (i.e. a gen_server or similar) to maintain the state
(which is in an ETS table).

> 
 > 2016-07-15 1:39 GMT+03:00 Alexandre Beniaminov <abeniaminov@REDACTED>:
 > 
 > > Thank you.
 > > You're right, and you've answered on part of my question:
 > >
 > > << Now, anything can happen in between, so in particular, ets:take/2 may
 > > return [] if the key was deleted or taken out by another process between
 > > the two calls.>>
 > >
 > > I would like to ask the community what do you think about to add  to ets
 > > module two atomic functions: ets:take_first/1 and ets:take_last/1  ?
 > >
 > > 2016-07-14 21:19 GMT+03:00 Jesper Louis Andersen <
 > > jesper.louis.andersen@REDACTED>:
 > >
 > >>
 > >> On Thu, Jul 14, 2016 at 8:06 PM, Alexandre Beniaminov <
 > >> abeniaminov@REDACTED> wrote:
 > >>
 > >>> atomic
 > >>
 > >>
 > >> You have to say what you expect to be atomic/linearizable. In your above
 > >> code, suppose you are being scheduled out between the call to ets:first/1
 > >> and ets:take/2. Now, anything can happen in between, so in particular,
 > >> ets:take/2 may return [] if the key was deleted or taken out by another
 > >> process between the two calls.
 > >>
 > >> But taken individually, the set of ets:first/1, ets:take/2 and
 > >> ets:lookup/2 ought to be linearizable. I.e., there is some point in time
 > >> (the atomic commit-point) at which ets:take/2 removes the objects. After
 > >> this commit-point first/1 and lookup/2 will not see the Key present in the
 > >> table anymore.
 > >>
 > >> So the question of if it is atomic or not depends on the precise
 > >> definition of what you ask.
 > >>
 > >>
 > >> --
 > >> J.
 > >>
 > >
 > >
 > >
 > > --
 > > С уважением,
 > > Александр Бениаминов
 > >
 > 
 > 
 > 
 > -- 
 > С уважением,
 > Александр Бениаминов
 > 
 > ----------------------------------------------------------------------
 > _______________________________________________
 > erlang-questions mailing list
 > erlang-questions@REDACTED
 > http://erlang.org/mailman/listinfo/erlang-questions

-- 



More information about the erlang-questions mailing list