Process Message Queues

Evans, Matthew mevans@REDACTED
Fri Apr 23 18:49:19 CEST 2010


Hi,

Question for you all.

The message queue in Erlang follows the following rule.

Messages are put in to the end of the queue, when the receive is processed the message is tested against the first pattern. If this matches this pattern it is removed from the queue, if it doesn't match then the message is matched against the second pattern and so on. If no patterns are matched then the message is put back on the queue and the next message is taken from the queue and so on...

So I spawn the following process, and send the 4 messages below:

==============================================

(scm@REDACTED)1> Pid = spawn(fun() -> receive message_a -> error_logger:info_msg("Got message_a~n"); message_b -> error_logger:info_msg("got message_b~n"); message_c -> receive message_d -> error_logger:info_msg("Got message_d~n") end end end).
<0.19842.0>
(scm@REDACTED)2> Pid ! hello.
hello
(scm@REDACTED)3> Pid ! goodbye.
goodbye
(scm@REDACTED)4> Pid ! message_d.
message_d
(scm@REDACTED)5> Pid ! message_e.
message_e
(scm@REDACTED)6> erlang:process_info(Pid,message_queue_len).
{message_queue_len,0}

===============================================

At this point wouldn't the message queue length be 4?

I know that message_d is in the queue since this works:

===============================================

(scm@REDACTED)7> Pid ! message_c.

=INFO REPORT==== 23-Apr-2010::16:39:47 ===
Got message_d
** at node scm@REDACTED **
message_c
(scm@REDACTED)56>

==============================================

I guess it's not too critical, but it makes it hard(er) to figure out if a message queue is filling up.

Thanks

Matt


More information about the erlang-questions mailing list