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

Dave Bryson daveb@REDACTED
Wed May 7 16:08:24 CEST 2008


On May 7, 2008, at 8:57 AM, Paul Fisher wrote:

> 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

Thanks for the response. So just to be clear, if the only access to  
the ets table is through calls to a gen_server process, it  
(gen_server) will ensure that only one process at a time can access  
the ets table?

Thanks again!
Dave



More information about the erlang-questions mailing list