New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reg_or_update_shared_local_counter #45
Comments
Thinking again, I see that my issue maybe solve having a |
How about this: safe_incr(C, Incr) ->
K = {c,l,C},
try gproc:update_shared_counter(K, Incr)
catch error:_ ->
try gproc:reg_shared(K, Incr), Incr
catch error:_ ->
gproc:update_shared_counter(K, Incr)
end
end. |
A reg_or_locate_shared() feels a little bit weird when I try to get a feeling for the semantics. Possibly an ensure_shared_reg(Key, Value)? |
The The What about Do you think that's a good enhancement to gproc? I advocate for this inclusion as it would be possible to keep shared counters without the trouble of building a safe critical session when creating/destroying shared counters. |
And now thinking about the counter, it would be a better approach to
|
I think the three catch levels should be enough:
The last increment should not have a catch, since it should fail for most other cases. I'm sure one can create a bizarre case where another process first creates, then deletes the counter... I'll think about what a new API function should look like. Ulf Wiger 25 jul 2013 kl. 23:06 skrev Eduardo Gurgel notifications@github.com:
|
Ok, thank you Ulf. I will just explain my use case: I have processes based on an associated id that when they spawn, they:
If another process with the same associated id spawn, they do the same. When they terminate, they decrement. If it reaches zero, destroy the shared counter. The creation/destruction can happen during the steps described above. Resuming it would be awesome to have:
Where if the counter reaches the unregvalue, for example 0, -1, it becomes unregistered. Maybe this is too crazy. Thank you again! 👍 |
Considering the fact that many already think that the gproc API is bloated, I think I'll pass on adding this function. ;-) |
I agree @uwiger and I think this change (erlang/otp#362) will solve my problems (considering that gproc will use it also if it gets merged). |
Indeed. |
I may be asking something stupid, but I need to know :)
I think I'm getting some race conditions using a shared local counter. Is there any way to register OR update a shared local counter? I imagine that's possible as the shared counter is unique and it must be linked to gproc itself, right?
If it's not possible, how could I work this out or may be add it to gproc? Any thoughts?
The text was updated successfully, but these errors were encountered: