[erlang-questions] clarify: order of messages

Adam Lindberg adam@REDACTED
Mon Nov 19 13:25:09 CET 2007


Ah, I had it for the other order, i.e. clauses first and message queue last,
my bad.

The following question would then be, why are there ever issues with one
process spamming the message queue making another process' messages not
appear? Matej's problem should not exist then, or am I missing something
here? Logically the receive statement should catch C2's messages at exactly
the ratio they are sent?

Cheers!
Adam

On Nov 19, 2007 11:10 AM, Paulo Sérgio Almeida <psa@REDACTED> wrote:

> Hi,
>
> Adam Lindberg wrote:
> > A basic check to do is to look at your receive statement.
> >
> > If it for example looks like this:
> >
> > receive
> >     {c1, Msg} ->
> >         do_c1_stuff();
> >     {c2, Msg} ->
> >         do_c2_stuff()
> > end
> >
> > In this case if there are always some messages from C1 in the message
> > queue they will be picked first, regardless of the order. This is called
>
> This is not true. Messages are looked at in arrival order, and for each
> message the guards are matched in program order. If the only messages in
> the mailbox are either {c1, Msg} or {c2, Msg} the above behaves the same
> as the code below.
>
> > selective receive. If you want to take the messages as they come you
> > should do something like this:
> >
> > receive
> >     {Sender, Msg} ->
> >         case Sender of
> >             c1 ->
> >                 do_c1_stuff();
> >             c2 ->
> >                 do_c2_stuff()
> >         end
> > end
> >
> > This way you will always pick a message, the first one to be in queue
> > (which matches pattern {A, B} of course) and _then_ look at the sender.
>
> Regards,
> /psa
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20071119/05140d3d/attachment.htm>


More information about the erlang-questions mailing list