<div dir="ltr"><div dir="ltr">Hi,<div><br></div><div>This is my updated code: <a href="https://pastebin.com/D9SAPUG8">https://pastebin.com/D9SAPUG8</a> please review again.</div><div><br></div><div>Please give me the pseudo code clue if there's more incorrectness to fix in my code.</div><div><br></div><div>And this is the output when i run my erlang program</div><div><br></div><div>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">Erlang/OTP 21 [erts-10.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1]</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">Eshell V10.2<span class="gmail-Apple-converted-space"> </span>(abort with ^G)</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">1> c(procslinked).</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">Recompiling /Users/okaprinarjaya/Oprek/Erlang-Oprek/oprek-lagi/src/procslinked.erl</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">/Users/okaprinarjaya/Oprek/Erlang-Oprek/oprek-lagi/src/procslinked.erl:2: Warning: export_all flag enabled - all functions will be exported</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">{ok,procslinked}</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">2> procslinked:starter().</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">Receive init_done from P1</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">Receive init_done from P2</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">Receive init_done from P3</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">{<0.91.0>,okbeud}</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">3> procslinked:call_the_first().</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">{<0.91.0>,"the_first_p()","Halo first p!"}</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">4> procslinked:call_the_second().</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">{<0.92.0>,"the_second_p()","Halo second p!"}</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">5> procslinked:call_the_third().</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">{<0.93.0>,"the_third_p()","Halo third p!"}</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">6> procslinked:call_the_first().<span class="gmail-Apple-converted-space"> </span></span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">{<0.91.0>,"the_first_p()","Halo first p!"}</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">7> procslinked:call_the_second().</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">{<0.92.0>,"the_second_p()","Halo second p!"}</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">8> procslinked:call_the_third().<span class="gmail-Apple-converted-space"> </span></span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">{<0.93.0>,"the_third_p()","Halo third p!"}</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">9><span class="gmail-Apple-converted-space"> </span></span></p></div><div><br></div><div>Thank you :)</div><div><br></div><div><br></div><div><br></div><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Pada tanggal Sel, 12 Mar 2019 pukul 02.13 bengt <<a href="mailto:cean.ebengt@gmail.com">cean.ebengt@gmail.com</a>> menulis:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;">Greetings,<br><br>The race is that starter/0 will return before any of the three processes have started. If you add a timer:sleep( 60000 ) before the calls to register/0 you will see this even if you do call_the_first/0 manually.<br><br>The pseudo code would be<br>My_pid = erlang:self(),<br><span style="background-color:rgb(255,255,255)">P =</span><span style="color:rgb(51,51,51);background-color:rgb(255,255,255);font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace,serif"> </span><span class="gmail-m_-681099599529850578kw3" style="font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace,serif;color:rgb(250,111,255)">spawn</span><span class="gmail-m_-681099599529850578br0" style="font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace,serif;color:rgb(16,154,184)">(</span><span style="color:rgb(51,51,51);background-color:rgb(255,255,255);font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace,serif">?</span><span class="gmail-m_-681099599529850578re4" style="font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace,serif;color:rgb(105,65,253)">MODULE</span><span class="gmail-m_-681099599529850578sy1" style="font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace,serif;color:rgb(107,184,16)">,</span><span style="color:rgb(51,51,51);background-color:rgb(255,255,255);font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace,serif"> </span><span style="color:rgb(51,51,51);background-color:rgb(255,255,255);font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace,serif">the_first_p</span><span class="gmail-m_-681099599529850578sy1" style="font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace,serif;color:rgb(107,184,16)">,</span><span style="color:rgb(51,51,51);background-color:rgb(255,255,255);font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace,serif"> </span><span class="gmail-m_-681099599529850578br0" style="font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace,serif;color:rgb(16,154,184)">[</span><span class="gmail-m_-681099599529850578br0" style="font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace,serif;background-color:rgb(255,255,255)"><font color="#333333">My_pid</font></span><span class="gmail-m_-681099599529850578br0" style="font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace,serif;color:rgb(16,154,184)">]</span><span class="gmail-m_-681099599529850578br0" style="font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace,serif;color:rgb(16,154,184)">),<br></span><span class="gmail-m_-681099599529850578sy1" style="font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace,serif">receive<br>{P, init_done} -> ok<br>end.</span><br><div><br></div>And then sending {erlang:self(), init_done} to My_pid (the process that started the_first_p).<br><br><div><br><blockquote type="cite"><div>On 11 Mar 2019, at 12:03, I Gusti Ngurah Oka Prinarjaya <<a href="mailto:okaprinarjaya@gmail.com" target="_blank">okaprinarjaya@gmail.com</a>> wrote:</div><br class="gmail-m_-681099599529850578Apple-interchange-newline"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi Andreas Schultz,</div><div dir="ltr"><br></div><div dir="ltr">>> The reason is that there is no guarantee that `call_the_third()` will be executed after any of the spawn has succeeded or the register was invoked.<br><div>1. Did you mean this code? <a href="https://pastebin.com/ECf3jhZ2" target="_blank">https://pastebin.com/ECf3jhZ2</a><br>2. and did you mean spawn_link/3 and register/2 is racy? </div><div>3. I've test this code many times, and never get error in each call_the_* function, even call_the_third/0 function. <br><br>Here: <a href="https://learnyousomeerlang.com/the-hitchhikers-guide-to-concurrency" target="_blank">https://learnyousomeerlang.com/the-hitchhikers-guide-to-concurrency</a>, and here: <a href="https://learnyousomeerlang.com/more-on-multiprocessing" target="_blank">https://learnyousomeerlang.com/more-on-multiprocessing</a> and <br>here: <a href="https://learnyousomeerlang.com/errors-and-processes" target="_blank">https://learnyousomeerlang.com/errors-and-processes</a> teach me to do that. Oh My God, where in this earth i can read the best erlang process tutorial ? so i can use erlang in the right way.</div><div><br></div><div>>> In order to get ordering guarantees you need to wait for the processes to be past the init stage. </div><div>>> The normal way to do that is to wait for a message from the init function of you child process.</div><div>Please give me a short pseudo-code clue to do this. I do really shocked because of this code: <a href="https://pastebin.com/ECf3jhZ2" target="_blank">https://pastebin.com/ECf3jhZ2</a> still not correct after 2 times revision. </div><div><br></div><div>Thank you :)</div><div><br></div><div><br></div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Pada tanggal Sen, 11 Mar 2019 pukul 14.55 Andreas Schultz <<a href="mailto:andreas.schultz@travelping.com" target="_blank">andreas.schultz@travelping.com</a>> menulis:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">You do realize that your code is still "racy" ?<div><br></div><div>Invoking it like</div><div><br></div><div> 2> procslinked:starter(), procslinked:call_the_third().</div><div><br></div><div>has a good chance of not producing the expected result. Most times it will simply fail with:</div><div><br></div><div><div> ** exception error: bad argument</div><div> in function procslinked:call_the_third/0 (procslinked.erl, line 54)</div></div><div><br></div><div>The reason is that there is no guarantee that `call_the_third()` will be executed after any of the spawn has succeeded or the register was invoked.</div><div>In order to get ordering guarantees you need to wait for the processes to be past the init stage. The normal way to do that is to wait for a message from the init function of you child process.</div><div><br></div><div>BTW: this is exactly what proc_lib:init_ack does, but I guess you are trying to implement that yourself as a learning exercise.</div><div><br></div><div>Andreas<br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">I Gusti Ngurah Oka Prinarjaya <<a href="mailto:okaprinarjaya@gmail.com" target="_blank">okaprinarjaya@gmail.com</a>> schrieb am So., 10. März 2019 um 23:38 Uhr:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">Hi Bengt,<div dir="auto"><br></div><div dir="auto">Thank you very much for all of your hints and suggestions. It's clear now. </div><div dir="auto"><br></div><div dir="auto"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Pada tanggal Sen, 11 Mar 2019 05.20, bengt <<a href="mailto:cean.ebengt@gmail.com" target="_blank">cean.ebengt@gmail.com</a>> menulis:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>I think your code is about learning erlang. Do that first. OTP is the next step.<br><br>Yes, splitting a gen_server into callback module and interface module is not the OTP way (as described in documentation), so while good for a beginner it can be considered bad style by experienced programmers.<br><br>Sorry, but I have not seen any tutorial about how to avoid thinking the same function/module is always in the same process. It is a very fundamental concept (them not being) in Erlang, so just keep it in mind. One way would be to try and make all your three functions the same function, just have different arguments to the loop. Then you must think about it.<br><br><div><br><blockquote type="cite"><div>On 10 Mar 2019, at 11:11, I Gusti Ngurah Oka Prinarjaya <<a href="mailto:okaprinarjaya@gmail.com" rel="noreferrer" target="_blank">okaprinarjaya@gmail.com</a>> wrote:</div><br class="gmail-m_-681099599529850578gmail-m_1125207073685011277m_-1852509069998413972m_-2910958684381146787Apple-interchange-newline"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi Bengt,<div><br></div><div>Thank you for your review :)</div><div><br></div><div>I don't quite understand with some of your thought. Then i hope you not mind to give more explanation.</div><div><br></div><div>>> Seasoned Erlang programmers will tell you this is not the OTP way, or a waste of modules</div><div>Did you mean my code here: <a href="https://pastebin.com/ECf3jhZ2" rel="noreferrer" target="_blank">https://pastebin.com/ECf3jhZ2</a> wasn't the OTP way? <br>I learn from here: <a href="https://learnyousomeerlang.com/errors-and-processes" rel="noreferrer" target="_blank">https://learnyousomeerlang.com/errors-and-processes</a> and i do really a beginner at programming with erlang.</div><div><br></div><div>>> So only do this until you have a better understanding.</div><div>What is that? Did you mean <i>doing one module with the interface functions to a gen_server and one module for the gen_server callbacks.?</i></div><div>or what?<br><br></div><div>>> Conflating the function (or even more often, module) and the process is a common mistake in the beginning. When my fellow programmers are experienced, but not used >> to process oriented programming.</div><div> Any tutorials / reference for me to avoid this mistake ?</div><div><br></div><div>Thank you :)</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Pada tanggal Min, 10 Mar 2019 pukul 14.49 bengt <<a href="mailto:cean.ebengt@gmail.com" rel="noreferrer" target="_blank">cean.ebengt@gmail.com</a>> menulis:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>Conflating the function (or even more often, module) and the process is a common mistake in the beginning. When my fellow programmers are experienced, but not used to process oriented programming, I have found that it helps to put the code that is run in different process in different modules. Ex: one module with the interface functions to a gen_server and one module for the gen_server callbacks. Seasoned Erlang programmers will tell you this is not the OTP way, or a waste of modules. So only do this until you have a better understanding.<br><br>bengt<br><div><br><blockquote type="cite"><div>On 10 Mar 2019, at 04:57, I Gusti Ngurah Oka Prinarjaya <<a href="mailto:okaprinarjaya@gmail.com" rel="noreferrer" target="_blank">okaprinarjaya@gmail.com</a>> wrote:</div><br class="gmail-m_-681099599529850578gmail-m_1125207073685011277m_-1852509069998413972m_-2910958684381146787gmail-m_4133803218338393271Apple-interchange-newline"><div><div dir="ltr"><div dir="ltr">Hi Bengt,<div><br></div><div>Thank you for the idea, <br><br>I've implement your idea, from performance side, i think using two version of function will have better performance because there's no need to checking using IF statement.</div><div><br></div><div>I worry at first to implement this idea, because i think different version of function will have different PID, hahaha it turns out exactly have same PID. <br>this is my new code <a href="https://pastebin.com/ECf3jhZ2" rel="noreferrer" target="_blank">https://pastebin.com/ECf3jhZ2</a> . Please review if there's any improvement needs. </div><div><br></div><div>Thank you </div><div><br></div><div><br></div><div><br></div><div><br></div><div><br><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Pada tanggal Min, 10 Mar 2019 pukul 05.23 bengt <<a href="mailto:cean.ebengt@gmail.com" rel="noreferrer" target="_blank">cean.ebengt@gmail.com</a>> menulis:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>Greetings,<br><br>The error happens the second time any of the three processes call erlang:register/2. They already registered themselves the first time. If you want this structure, but not the error, you have to do the register before starting the loop. Eg, split the functions into two. One that do the register and then calls the second that does the loop.<br><br>bengt<br><div><br><blockquote type="cite"><div>On 9 Mar 2019, at 14:41, I Gusti Ngurah Oka Prinarjaya <<a href="mailto:okaprinarjaya@gmail.com" rel="noreferrer" target="_blank">okaprinarjaya@gmail.com</a>> wrote:</div><br class="gmail-m_-681099599529850578gmail-m_1125207073685011277m_-1852509069998413972m_-2910958684381146787gmail-m_4133803218338393271gmail-m_1841625249326328505Apple-interchange-newline"><div><div dir="ltr"><div dir="ltr">Hi Attila Rajmund Nohl,<div><br></div><div>After i implement your suggestion, i get error when execute any of function call_the_*_p()</div><div>for example:<br><br></div><div><div style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-681099599529850578gmail-m_1125207073685011277m_-1852509069998413972m_-2910958684381146787gmail-m_4133803218338393271gmail-m_1841625249326328505gmail-s1" style="font-variant-ligatures:no-common-ligatures">3> newbie:starter().</span></div><div style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-681099599529850578gmail-m_1125207073685011277m_-1852509069998413972m_-2910958684381146787gmail-m_4133803218338393271gmail-m_1841625249326328505gmail-s1" style="font-variant-ligatures:no-common-ligatures"><0.112.0></span></div><div style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-681099599529850578gmail-m_1125207073685011277m_-1852509069998413972m_-2910958684381146787gmail-m_4133803218338393271gmail-m_1841625249326328505gmail-s1" style="font-variant-ligatures:no-common-ligatures">4> newbie:call_the_second().</span></div><div style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-681099599529850578gmail-m_1125207073685011277m_-1852509069998413972m_-2910958684381146787gmail-m_4133803218338393271gmail-m_1841625249326328505gmail-s1" style="font-variant-ligatures:no-common-ligatures">=ERROR REPORT==== 9-Mar-2019::20:35:15.069388 ===</span></div><div style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-681099599529850578gmail-m_1125207073685011277m_-1852509069998413972m_-2910958684381146787gmail-m_4133803218338393271gmail-m_1841625249326328505gmail-s1" style="font-variant-ligatures:no-common-ligatures">Error in process <0.113.0> with exit value:</span></div><div style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-681099599529850578gmail-m_1125207073685011277m_-1852509069998413972m_-2910958684381146787gmail-m_4133803218338393271gmail-m_1841625249326328505gmail-s1" style="font-variant-ligatures:no-common-ligatures">{badarg,[{erlang,register,[pidsecondp,<0.113.0>],[]},</span></div><div style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-681099599529850578gmail-m_1125207073685011277m_-1852509069998413972m_-2910958684381146787gmail-m_4133803218338393271gmail-m_1841625249326328505gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-m_-681099599529850578gmail-m_1125207073685011277m_-1852509069998413972m_-2910958684381146787gmail-m_4133803218338393271gmail-m_1841625249326328505gmail-Apple-converted-space"> </span>{newbie,the_second_p,0,</span></div><div style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-681099599529850578gmail-m_1125207073685011277m_-1852509069998413972m_-2910958684381146787gmail-m_4133803218338393271gmail-m_1841625249326328505gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-m_-681099599529850578gmail-m_1125207073685011277m_-1852509069998413972m_-2910958684381146787gmail-m_4133803218338393271gmail-m_1841625249326328505gmail-Apple-converted-space"> </span>[{file,"/Users/okaprinarjaya/Oprek/Erlang-Oprek/oprek-lagi/src/newbie.erl"},</span></div><div style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-681099599529850578gmail-m_1125207073685011277m_-1852509069998413972m_-2910958684381146787gmail-m_4133803218338393271gmail-m_1841625249326328505gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-m_-681099599529850578gmail-m_1125207073685011277m_-1852509069998413972m_-2910958684381146787gmail-m_4133803218338393271gmail-m_1841625249326328505gmail-Apple-converted-space"> </span>{line,17}]}]}</span></div><div style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span class="gmail-m_-681099599529850578gmail-m_1125207073685011277m_-1852509069998413972m_-2910958684381146787gmail-m_4133803218338393271gmail-m_1841625249326328505gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span class="gmail-m_-681099599529850578gmail-m_1125207073685011277m_-1852509069998413972m_-2910958684381146787gmail-m_4133803218338393271gmail-m_1841625249326328505gmail-s1" style="font-variant-ligatures:no-common-ligatures">{<0.113.0>,"the_second_p()","Halo second p!"}</span></div></div><div><br></div><div>This is my new modified code <a href="https://pastebin.com/iYCxkkuz" rel="noreferrer" target="_blank">https://pastebin.com/iYCxkkuz</a></div><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Pada tanggal Jum, 8 Mar 2019 pukul 21.03 Attila Rajmund Nohl <<a href="mailto:attila.r.nohl@gmail.com" rel="noreferrer" target="_blank">attila.r.nohl@gmail.com</a>> menulis:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I Gusti Ngurah Oka Prinarjaya <<a href="mailto:okaprinarjaya@gmail.com" rel="noreferrer" target="_blank">okaprinarjaya@gmail.com</a>> ezt írta<br>
(időpont: 2019. márc. 8., P, 12:11):<br>
><br>
> Hi Folks,<br>
><br>
> I need your help to review my code. I create and linking 3 process manually without using recursive. And inside p1 and p2 i using IF statement to check to make sure spawning process will only once.<br>
><br>
> I mean, is part code below is a good idea?<br>
><br>
> IsPidExists = whereis(xxx),<br>
> if IsPidExists =:= undefined -><br>
> Pid = spawn_link(?MODULE, the_p, []),<br>
> register(xxx, Pid);<br>
> true -> true<br>
> end,<br>
<br>
Generally this is not a good idea, there's a race condition between<br>
checking that the process is registered (the whereis/1 call) and<br>
registering the new process. A better idea is to start the process and<br>
let the process itself to register. If register fails, it means that<br>
there's already a process registered, so the just started process can<br>
terminate. So your code could look like something like this:<br>
<br>
starter() -><br>
spawn(?MODULE, the_first_p, []).<br>
<br>
the_first_p() -><br>
register(pidfirstp, self()),<br>
spawn_link(?MODULE, the_second_p, []),<br>
...<br>
the_first_p().<br>
<br>
Actually if the register call fails, it throws a badarg and the<br>
process dies automatically, simplifying the code.<br>
</blockquote></div>
_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org" rel="noreferrer" target="_blank">erlang-questions@erlang.org</a><br><a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br></div></blockquote></div><br></div>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" rel="noreferrer" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div>
</div></blockquote></div><br></div>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" rel="noreferrer" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div>
</div></blockquote></div><br></div>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" rel="noreferrer" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div></div></div>-- <br><div dir="ltr" class="gmail-m_-681099599529850578gmail-m_1125207073685011277gmail_signature"><div dir="ltr"><span style="font-family:monospace,monospace">-- <br>Dipl.-Inform. Andreas Schultz<br><br>----------------------- enabling your networks ----------------------<br>Travelping GmbH Phone: +49-391-81 90 99 0<br>Roentgenstr. 13 Fax: +49-391-81 90 99 299<br>39108 Magdeburg Email: <a href="mailto:info@travelping.com" target="_blank">info@travelping.com</a><br>GERMANY Web: <a href="http://www.travelping.com/" target="_blank">http://www.travelping.com</a><br><br></span><div><span style="font-family:monospace,monospace">Company Registration: Amtsgericht Stendal Reg No.: HRB 10578</span></div><span style="font-family:monospace,monospace">Geschaeftsfuehrer: Holger Winkelmann VAT ID No.: DE236673780<br>---------------------------------------------------------------------</span></div></div>
</blockquote></div>
</div></blockquote></div><br></div>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div>