[erlang-questions] compare and set semantics using ets?

Dmitry Kolesnikov dmkolesnikov@REDACTED
Mon Jan 14 13:45:56 CET 2013


Hello,

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.

- Dmitry

On Jan 14, 2013, at 2:08 PM, Anton Lebedevich <mabrek@REDACTED> wrote:

> Hello.
> 
> 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.
> 
> Regards,
> Anton Lebedevich.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list