Erlang Process doesn't receive messages

Serge Aleynikov serge@REDACTED
Mon Jun 9 18:47:49 CEST 2003


During the following test, I discovered a non-intuitive behavior that 
I'd appreciate to receive some help with.

Given two processes: client (shown as a Erlang shell process), and 
server.  The server implements the following loop in a process separate 
from client:

loop() ->
     receive
         stop ->
             stopped;
         {test, From, Arg} ->
             timer:sleep(3000),
             From ! Arg,
             loop()
     end.

Perform the commands below from the client process shell.  What is not 
clear in this code is that despite the fact that the client has messages 
in its mailbox, the receive command times out without removing messages 
from the mailbox.

Can anyone explain this?

Thanks,

Serge

94> Pid = server:start().
<0.139.0>
95> process_info(self(), messages).
{messages,[]}
96> Pid ! {test, self(), 1}.
{test,<0.142.0>,1}
97> process_info(self(), messages).
{messages,[]}
98> process_info(self(), messages).
{messages,[1]}
99> receive Msg -> Msg after 3000 -> timeout end.
1
100> Pid ! {test, self(), 1}.
{test,<0.142.0>,1}
101> Pid ! {test, self(), 2}.
{test,<0.142.0>,2}
102> process_info(self(), messages).
{messages,[1]}
103> process_info(self(), messages).
{messages,[1]}
104> process_info(self(), messages).
{messages,[1,2]}
105> receive Msg -> Msg after 3000 -> timeout end.
1
106> receive Msg -> Msg after 3000 -> timeout end.
timeout
107> receive Msg -> Msg after 3000 -> timeout end.
timeout
108> process_info(self(), messages).
{messages,[2]}
109> os:type().
{win32,nt}
------------------------




More information about the erlang-questions mailing list