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

Paul Fisher <>
Wed May 7 16:20:20 CEST 2008

On Wed, 2008-05-07 at 09:08 -0500, Dave Bryson wrote:
> On May 7, 2008, at 8:57 AM, Paul Fisher wrote:
> > 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?

Since the gen_server process is the only one interacting with the ets
table, and it processes messages one-at-a-time, then there is only one
process accessing the table.  Now this means that you need to wrap the
read/increment/write into processing that the gen_server does in
response to a single message, which I did not make clear in the initial
response (e.g. gen_server:call( my_server, {counter_increment, 1} ) ).


Robert Virding's First Rule:
"Any sufficiently complicated concurrent program in another language
contains an ad hoc, informally-specified, bug-ridden, slow
implementation of half of Erlang."

More information about the erlang-questions mailing list