[erlang-questions] Preventing a race condition when using dets/ets

Paul Fisher <>
Wed May 7 15:57:15 CEST 2008


On Wed, 2008-05-07 at 08:48 -0500, Dave Bryson wrote:
> Say for example I have the following code:
> 
> {_,N} = ets:lookup(?MODULE,counter),
> ok = ets:insert(?MODULE, {counter, N+1}).

Two options:
1) use ets:update_counter/3, if it is really an integer value with the
table being public
2) have a gen_server process "own" the ets table and perform all
operations on behalf of callers (gen_server:call/2, 3) with the table
being private


-- 
paul




More information about the erlang-questions mailing list