[erlang-questions] Noob question: Need some help to limit process spawing
Jesper Louis Andersen
jesper.louis.andersen@REDACTED
Mon Aug 17 10:35:46 CEST 2015
On Sun, Aug 16, 2015 at 6:27 PM, avinash D'silva <evnix.com@REDACTED>
wrote:
> I solved the problem by using a *mutex*:
> but I am not sure if this is the right way to do it in Erlang or if there
> are better ways of doing the same?
>
The problem is you are using pg2 which provides different characteristics
from what you expect. The purpose of pg2 is to build a group of processes,
for instance 5 such processes.
Internally it uses the `global` module to run transactions on every node
joined in the cluster. It is not clear to me what consistency level this
implies. A guess would be sequential consistency.
The result is that between you getting the members and you joining, things
can happen, and you have a race there which you then have to solve.
A good guess on a solution would be to use either local registration, or
the global module. There, you would have the ability to boot out any
process which is being started on top of another one, so to speak. Also
`global:set_lock/3` and `global:trans/2,3,4` may be of interest to you.
--
J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150817/d2a8ef76/attachment.htm>
More information about the erlang-questions
mailing list