Erlang Process doesn't receive messages

Serge Aleynikov <>
Mon Jun 9 20:26:54 CEST 2003


Thanks.  I had a feeling that it's somehow related to side-effects of 
the shell, because when the "receive Msg -> Msg after 3000 -> timeout 
end." is incapsulated in a function, when that function is called the 
message queue poll worked correctly.

Serge

Vladimir Sekissov wrote:
> Good day,
> 
> 4> receive Msg -> Msg after 3000 -> timeout end.
> 1
> 5> Msg.
> 1
> 6> 
> 
> You exported Msg declaration from `receive' and in second `receive'
> tried to compare with pattern Msg=1.
> 
> Compiler warns you in such cases.
> 
> Best Regards,
> Vladimir Sekissov
> 
> serge> During the following test, I discovered a non-intuitive behavior that 
> serge> I'd appreciate to receive some help with.
> serge> 
> serge> Given two processes: client (shown as a Erlang shell process), and 
> serge> server.  The server implements the following loop in a process separate 
> serge> from client:
> serge> 
> serge> loop() ->
> serge>      receive
> serge>          stop ->
> serge>              stopped;
> serge>          {test, From, Arg} ->
> serge>              timer:sleep(3000),
> serge>              From ! Arg,
> serge>              loop()
> serge>      end.
> serge> 
> serge> Perform the commands below from the client process shell.  What is not 
> serge> clear in this code is that despite the fact that the client has messages 
> serge> in its mailbox, the receive command times out without removing messages 
> serge> from the mailbox.
> serge> 
> serge> Can anyone explain this?
> serge> 
> serge> Thanks,
> serge> 
> serge> Serge
> serge> 
> serge> 94> Pid = server:start().
> serge> <0.139.0>
> serge> 95> process_info(self(), messages).
> serge> {messages,[]}
> serge> 96> Pid ! {test, self(), 1}.
> serge> {test,<0.142.0>,1}
> serge> 97> process_info(self(), messages).
> serge> {messages,[]}
> serge> 98> process_info(self(), messages).
> serge> {messages,[1]}
> serge> 99> receive Msg -> Msg after 3000 -> timeout end.
> serge> 1
> serge> 100> Pid ! {test, self(), 1}.
> serge> {test,<0.142.0>,1}
> serge> 101> Pid ! {test, self(), 2}.
> serge> {test,<0.142.0>,2}
> serge> 102> process_info(self(), messages).
> serge> {messages,[1]}
> serge> 103> process_info(self(), messages).
> serge> {messages,[1]}
> serge> 104> process_info(self(), messages).
> serge> {messages,[1,2]}
> serge> 105> receive Msg -> Msg after 3000 -> timeout end.
> serge> 1
> serge> 106> receive Msg -> Msg after 3000 -> timeout end.
> serge> timeout
> serge> 107> receive Msg -> Msg after 3000 -> timeout end.
> serge> timeout
> serge> 108> process_info(self(), messages).
> serge> {messages,[2]}
> serge> 109> os:type().
> serge> {win32,nt}
> serge> ------------------------




More information about the erlang-questions mailing list