Atomic ets

Mats Cronqvist mats.cronqvist@REDACTED
Tue Dec 13 17:34:32 CET 2005


   years ago, i suggested to OTP that adding atomic expressions (similar to 
block expressions) to Erlang would allow one to solve this kind of problems. like;

atomic
   case ets:lookup(a,b) of
     [] -> ets:insert(a,c);
     _ -> ok
   end
end

   inside the atomic block you'd be guaranteed not to be scheduled out.
   i don't remember if they laughed hysterically or just waited for me to go 
away, but nothing came of it. quite possibly there were good reasons for that.

   mats

p.s. of course it'd be really easy to crush the emulator with this feature. i 
don't think that's a good reason for nixing it though.


Ulf Wiger (AL/EAB) wrote:
>  
> Thomas Lindgren wrote:
> 
>>1. Am I being dense in writing my ets code? Are there simple, 
>>useful ways to write ets code that avoids the problem of 
>>getting preempted between, say, a lookup and an insert?
> 
> 
> Well, yes (on the second question). You can make sure that 
> all updates to a table are serialized using e.g. a gen_server.
> 
> You can then pass the server an update fun if you want.
> 
> /Uffe



More information about the erlang-questions mailing list