<div dir="ltr">Thank you, <span style="font-family:arial,sans-serif;font-size:13px">Jachym and </span><span style="font-family:arial,sans-serif;font-size:13px">Hynek.</span></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 3, 2014 at 11:30 AM, Jachym Holecek <span dir="ltr"><<a href="mailto:freza@circlewave.net" target="_blank">freza@circlewave.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># Gadi Srebnik 2014-11-01:<br>
<span class="">> How safe it is to use controlling_process after spawn? I am using<br>
> additional gen_tcp:controlling_process inside the Mod:Fun itself after few<br>
> additional commands. Is it possible that process will not be owner by then?<br>
<br>
</span>Yes, there's a race condition there, you need explicit synchronization to<br>
be safe:<br>
<br>
start_worker(Sock) -><br>
Pid = erlang:spawn(?MODULE, worker_init, [Sock]),<br>
gen_tcp:controlling_process(Sock, Pid),<br>
Pid ! proceed.<br>
<br>
worker_init(Sock) -><br>
receive<br>
proceed -><br>
%% Okay now we actually own it.<br>
worker_loop(Sock)<br>
after 1000 -><br>
exit(things_seem_awfully_slow_today)<br>
end.<br>
<br>
I wish there were a variant of controlling_process that would advise the<br>
new owner automatically by sending {tcp_handover, Sock, Info} to it, the<br>
last item being arbitrary term passed by previous owner. No idea how hard<br>
would it be to implement.<br>
<br>
BR,<br>
-- Jachym<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div><div style="color:rgb(80,0,80)"><font color="#999999" face="arial, helvetica, sans-serif">Gadi Srebnik</font></div><div><font color="#999999" face="arial, helvetica, sans-serif">VP Communications</font></div><div style="color:rgb(80,0,80)"><font color="#999999" face="arial, helvetica, sans-serif"> m: +972 54 5929261</font></div><div style="color:rgb(80,0,80)"><font color="#999999" face="arial, helvetica, sans-serif" size="1"><br></font></div><div style="color:rgb(80,0,80)"><p style="margin:0in 0in 0.0001pt"><img src="http://www.rounds.com/blog/wp-content/uploads/2012/12/roundsLogos_fun_together_now_signature-01.jpg"></p></div></div></div></div></div>
</div>