<div dir="ltr">Isn't it obvious? Appending head is O(1) operation, removing head is also O(1) operation. Since there is not any guarantee in which order messages should be returned, it is the obvious simplest solution. Your testing code is very uncommon in a real application. There are usually two different processes which schedule messages and the effect is unnoticeable because their ordering is not defined.</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 9, 2015 at 1:32 PM, Dao Gui <span dir="ltr"><<a href="mailto:guidao1013@gmail.com" target="_blank">guidao1013@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span style="font-size:14px">talk is cheap, show the code. ^_^</span><div style="font-size:14px"><br></div><div style="font-size:14px"><div>-module(t).</div><div>-export([main/0]).</div><div>main() -></div><div>                Pid = spawn(fun()->test2() end),</div><div>                erlang:send_after(1000,Pid, 1),</div><div>                erlang:send_after(1000,Pid,2).</div><div>test2() -></div><div><br></div><div>                receive </div><div>                                A -> </div><div>                                        io:format("dddd:~p~n",[A]),</div><div>                                        test2()</div><div>                end.</div></div><div style="font-size:14px"><br></div><div style="font-size:14px">--------------------------------------------------------------------------------------------------------</div><div style="font-size:14px">this output is:</div><div style="font-size:14px">dddd:2<br></div><div style="font-size:14px">dddd:1<br></div><div style="font-size:14px"><br></div><div style="font-size:14px">then , I find this in time.c</div><div style="font-size:14px"><br></div><div style="font-size:14px"><div><b>    /* insert at head of list at slot */</b></div><div><b>    p->next = tiw[tm];</b></div><div><b>    p->prev = NULL;</b></div><div><b>    if (p->next != NULL)</b></div><div><b><span style="white-space:pre-wrap">   </span>p->next->prev = p;</b></div><div><b>    tiw[tm] = p;</b></div></div><div style="font-size:14px"><br></div><div style="font-size:14px">it insert head when we insert message</div><div style="font-size:14px"><br></div><div style="font-size:14px"><br></div><div style="font-size:14px"><div><b>/* Remove from list */</b></div><div><b>remove_timer(p);</b></div><div><b>*timeout_tail = p;<span style="white-space:pre-wrap">   </span>/* Insert in timeout queue */</b></div><div><b>timeout_tail = &p->next;</b><b><span style="white-space:pre-wrap">               </span></b></div></div><div style="font-size:14px"><br></div><div style="font-size:14px">it insert tail when it timeout.</div><div style="font-size:14px"><br></div><div style="font-size:14px">----------------------------------------------------------------------------</div><div style="font-size:14px">Q: but why ? if message timeout, we can insert head. it can keep the order of message. why don't do this? </div><div style="font-size:14px"><br></div><div style="font-size:14px">other: my English is poor. if something wrong, i hope you forgive me.</div></div>
<br>_______________________________________________<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>
<br></blockquote></div><br></div>