[erlang-questions] ets:select_delete not atomic?

Sverker Eriksson sverker@REDACTED
Mon Aug 12 16:33:44 CEST 2019

On mån, 2019-08-12 at 14:16 +0200, Oliver Bollmann wrote:
> Hi,
> EtsName = ets:new(test,[named_table,ordered_set]),
> Res = ets:select_delete(EtsName,[{{Key},[],[true]}]).
> Res should be 1 or 0!
> But if i do this with a lot of process, at the same time,
> it happend that two process get 1!
> Start with: ets:insert(EtsName,{Key}).
> Process One: ets:select_delete(EtsName,[{{Key},[],[true]}]).
> Process Two: ets:select_delete(EtsName,[{{Key},[],[true]}]).
> Process One get 1 AND Process Two get 1, with the same key, of course! 
> Is this correct?

No, that does not seem right.

The table traversals done by ets:select* and ets:match* functions are not
atomic, but the operation done on each found object should be atomic.

That is, if you do ets:insert(T,{Key}) once and then several
ets:select_delete(T, [{{Key},[],[true]}]) in parallel, only of of them should
find {Key} and delete it.

What OTP version is this?


More information about the erlang-questions mailing list