[erlang-questions] compare and set semantics using ets?
Mon Jan 14 13:45:56 CET 2013
not it is not possible w/o touching VM.
I've started to implement "advanced counters" via dedicated process.
BTW, you approach with manager process is aligned with OTP principles.
On Jan 14, 2013, at 2:08 PM, Anton Lebedevich <> wrote:
> Is it possible to implement atomic compare-and-set semantics using ets?
> Currently it allows to increment counter and return new value atomically
> but "don't touch the counter if someone touched it before me" is quite
> tricky or impossible to achieve.
> I might be digging in a wrong direction, the problem is following:
> There is a shared limited resource (i.e. memory). Incoming requests
> require some (specified in headers) amount of the resource which is
> freed on completion. Each request is served via it's own process. The
> process needs to allocate the resource and serve the request or refuse
> if there is not enough resource available.
> Simple (and slow on high request rate) solution is to implement
> gen_server that handles allocation requests and either grants them or
> refuses based on calculated total.
> https://github.com/ferd/dispcount uses ets counter with known initial
> value to implement compare-and-set but in my case the initial value
> (currently allocated amount) is unknown.
> Anton Lebedevich.
> erlang-questions mailing list
More information about the erlang-questions