What about having init:halt() send a sync'd message to the group leader to shut down?<div>Once the group leader shuts down and returns then init:halt() will exit.</div><div>Even without a group-leader shutdown, even having the group-leader return a ping-type message could unblock the init:halt() and ensure that you've processed the messages at least that far, thus "flushing the buffer."</div>
<div><br></div><div>-mox</div><div><div class="gmail_quote"><br></div><div class="gmail_quote">On Mon, Apr 4, 2011 at 10:24 AM, Scott Lystig Fritchie <span dir="ltr"><<a href="mailto:fritchie@snookles.com">fritchie@snookles.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">Matthias Lang <<a href="mailto:matthias@corelatus.se">matthias@corelatus.se</a>> wrote:<br>
<br>
</div>ml> What IO situation is the code above trying to take care of? Why not<br>
ml> just<br>
<br>
ml> my_halt(Reason) -><br>
ml>    init:stop(Reason),<br>
ml>    receive after infinity -> ok<br>
ml> end.<br>
<br>
ml> Not sure if this is a bug or if I'm just expecting too much, but<br>
ml> tossing output by default doesn't seem nice because it leads to code<br>
ml> that seems to work except when it doesn't.<br>
<br>
IIRC the stuff scribbled to the console via io:format() is actually done<br>
by sending messages to the group leader process.  You're at the<br>
scheduler's whim to decide whether the group leader gets executed &<br>
processes the I/O requests before the VM halts.<br>
<br>
Having said that, I've been bitten by this same concurrency feature.<br>
C/Ruby/Python folks don't expect the feature.  Even never-touched-<br>
another-language Erlang hackers may not expect it.  But short of having<br>
a function like like escript:halt/1 to take the place of your my_halt()<br>
function ... and a whole lot of doc additions to point out that calling<br>
io:format() is **not** a thin wrapper around the syscall/stdlib calls:<br>
<br>
    write(1, str, strlen(str));<br>
    /* OR */<br>
    fwrite(str, strlen(str), 1, stdout);<br>
<br>
... I can't think of an easier fix.  (Perhaps I simply need more<br>
coffee?)<br>
<font color="#888888"><br>
-Scott<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br></div>