<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><BR class="khtml-block-placeholder"><DIV><BLOCKQUOTE type="cite"><DIV class="Section1"><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">Is there an equivalent function in <SPAN class="SpellE">Erlang</SPAN> to “C <SPAN class="SpellE">pthreads</SPAN> join”? This can semantically be implemented with linked process with ‘receive to exit’, but what I want to know is whether there is a direct BIF to call after spawn?</SPAN></FONT></P></DIV></BLOCKQUOTE><DIV>You are on the right track with "receive to exit". One nice trick you can do in erlang is to return the result of some short lived process in the exit message. This saves having to send a result message as well as handling the EXIT. Sketch of code here:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>spawn(fun() -> short_lived() end),</DIV><DIV>receive</DIV><DIV> {'EXIT', {ok, Result}} -></DIV><DIV> result_proc(Result);</DIV><DIV> {'EXIT', Error} -></DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>log_error(Error)</DIV><DIV>end.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>short_lived() -></DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>Res = do_work(),</DIV><DIV> exit({ok, Res}).</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Sean</DIV><DIV><BR class="khtml-block-placeholder"></DIV><BR><BLOCKQUOTE type="cite"><DIV class="Section1"><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"><O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial"><O:P> </O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">Thanks,<O:P></O:P></SPAN></FONT></P><P class="MsoNormal"><FONT size="2" face="Arial"><SPAN style="font-size:10.0pt; font-family:Arial">N.Piriyatheepan<O:P></O:P></SPAN></FONT></P> </DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_______________________________________________</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">erlang-questions mailing list</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</A></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="http://www.erlang.org/mailman/listinfo/erlang-questions">http://www.erlang.org/mailman/listinfo/erlang-questions</A></DIV> </BLOCKQUOTE></DIV><BR></BODY></HTML>