[erlang-questions] Can Erlang messages be delivered out of order?

Hynek Vychodil <>
Sun Jan 25 14:45:51 CET 2009


On Sun, Jan 25, 2009 at 12:56 PM, Sergey S <> wrote:

> Hello.
>
> > If you read the manual, you'll find that each process have it's own
> receive
> > queue, and that new messages are always placed at the end of that queue.
> > So, for you example, yes.
>
> Thanks. I didn't know how message passing is implemented. It got away
> from me, while I was reading docs on that.
>
> > However, your example program don't work the way you seem to expect
> anyway.
> <skipped>
> > So, even if the messages would have been pleced in the wrong order, your
> program would have worked just as fine.
>
> Those receive-statements were supposed to illustrate the order in
> which I expect messages will be delivered. But you are right in that
> program will receive all the message independent from the order. So it
> was not very good example to illustrate what I expect =)
>
> --
> Sergey
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>

If you want test it, here is example of testing module code:

-module(messageorder).

-export([test/0]).

test() ->
    process_flag(trap_exit, true),
    Parent = self(),
    flush(),
    Pid = spawn_link(fun() ->
                        Parent ! hello,
                        Parent ! world
                end),
    receive X -> hello = X end,
    receive Y -> world = Y end,
    receive Z -> {'EXIT', Pid, normal} = Z end,
    ok.

flush() ->
    receive _ -> flush()
    after 0 -> ok
    end.

-- 
--Hynek (Pichi) Vychodil

Analyze your data in minutes. Share your insights instantly. Thrill your
boss.  Be a data hero!
Try Good Data now for free: www.gooddata.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090125/0522602a/attachment.html>


More information about the erlang-questions mailing list