<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 8, 2014 at 10:30 PM, <span dir="ltr"><<a href="mailto:H.Li@kent.ac.uk" target="_blank">H.Li@kent.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="overflow:hidden">I don't quite understand what erlang:bif_return_trap/1 does, and am<br>
confused why so many processes got stuck in this function.</div></blockquote></div><br>It is a Red Herring(tm)[0].</div><div class="gmail_extra"><br></div><div class="gmail_extra">Suppose the VM has to execute some BIF, link for example, for a process P. In the course of linking P to another process, the VM will figure out it needs to send a distributed message and that the distribution channel is clogged up. So the VM suspends P until the link message has succeeded. The problem now, is that we can't return to P, since it is suspended, and we have a result from the link function we wish to tell P once it is unsuspended. We can bump the reduction counter to 0, but this will still have P execute until the next reduction counter bump, which is not what we want.</div><div class="gmail_extra"><br></div><div class="gmail_extra">This is where bif_return_trap/1 comes in. We mangle the state of P such that when it unsuspends, it is executing bif_return_trap/1 and the value is ready for returning. That is, we arrange it such that bif_return_trap/1 is an immediate continuation of the program.</div><div class="gmail_extra"><br></div><div class="gmail_extra">This is why it is a red herring. Some other function has executed and mangled your current state. If distribution/ports are in play, consider using erlang:system_monitor/2 to watch over the errornous state. There are some old posts by Paul Davis and Scott L. Fritchie which could be somewhat related:</div><div class="gmail_extra"><br></div><div class="gmail_extra"><a href="http://erlang.org/pipermail/erlang-questions/2012-December/071157.html">http://erlang.org/pipermail/erlang-questions/2012-December/071157.html</a><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">[0] Ni! Ni! Ni! Ni! Ni!<br><br clear="all"><div><br></div>-- <br>J.
</div></div>