[erlang-questions] Replacing ets tables - renaming and race condition
Ulf Wiger (TN/EAB)
ulf.wiger@REDACTED
Wed Apr 4 13:22:16 CEST 2007
Apologies, btw. I have my wiger.net emails forwarded to
my gmail account, but the gmail account doesn't subscribe
to the list. That's why this post didn't make it through
to the list.
BR,
Ulf W
> -----Original Message-----
> From: erlang-questions-bounces@REDACTED
> [mailto:erlang-questions-bounces@REDACTED] On Behalf Of
> Paulo Sérgio Almeida
> Sent: den 4 april 2007 12:57
> To: Ulf Wiger
> Cc: erlang-questions@REDACTED
> Subject: Re: [erlang-questions] Replacing ets tables -
> renaming and race condition
>
> Ulf, even if my problem is much simpler than if there were
> dependencies between lookups, it is not that simple ...
>
> Namely, your sketched solution still has a race condition.
>
> > Tab = ets:new(tmp, []),
> > compute(Tab),
> > ets:insert(switch_table, {current, Tab}).
>
> If some process does:
>
> > lookup(Key) ->
> > Tab = ets:lookup_element(switch, current, 2),
> > ets:lookup(Tab, Key).
>
> it could do the lookup_element, but be interrupted before
> doing the lookup. This means the lookup could be to a table
> that no longer exists if the recompute is:
>
> > recompute() ->
> > Old = ets:lookup_element(switch, current, 2),
> > New = ets:new(tmp, []),
> > compute(New),
> > ets:insert(switch, {current, New}),
> > ets:delete(Old).
>
> So, we still have a problem :)
> Moreover, this switch table would make usage a bit unpleasant.
>
> To make this thread more interesting, as mnesia/ets is the
> erlang "shared memory", I am curious how frequently do people
> encounter these kind of race conditions and what (minimal)
> support there should be towards enabling fast accesses while
> ensuring something, like atomicity (e.g. like update_counter).
>
> What do you think about my "rename with forced atomic delete"
> proposal.
> I think it could have its place.
>
> Regards,
> Paulo
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
More information about the erlang-questions
mailing list