<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Aug 16, 2015 at 6:27 PM, avinash D'silva <span dir="ltr"><<a href="mailto:evnix.com@gmail.com" target="_blank">evnix.com@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>I solved the problem by using a <b>mutex</b>: </div><div>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?</div></blockquote></div><br></div><div class="gmail_extra">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.<br><br>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.<br><br></div><div class="gmail_extra">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.<br><br></div><div class="gmail_extra">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.<br></div><div class="gmail_extra"><br clear="all"><br>-- <br><div class="gmail_signature">J.</div>
</div></div>