Open horvand opened 9 years ago
@lucafavatella You mean the ETS version of insert_new/2
and lookup()
are not atomic?
@horvand I cannot look into this more at the moment. I remember Ed and I looked at both ETS and Mnesia as backends (I am aware of insert_new) and 2 different versions of the rules of the semantics at direct contact with cache (eval_something).
In the git history you shall find my partial revert of a commit by Ed on the matter.
What I remember off the top of my head at the moment is that unless either OTP was including https://github.com/erlang/otp/pull/387 (or similar) correctness with ETS was not guaranteed.
Caveats:
Introduced a gen_server
to serialise inserts. IMHO, this should provide similar guaranteed as the Mnesia version does.
However, this means more or less having a global lock on the whole cache for writes.
Do we have ets:take/2 yet? Looks like it has been accepted, also looks like there is a lock there.
Process reads cache, finds neither calc nor value, writes calc. Are all the previous actions performed atomically?