[erlang-questions] confusing message behavior

Steven Grady sgrady@REDACTED
Wed Oct 22 21:14:20 CEST 2008


Can someone explain why some messages are thrown away when doing a  
"receive" from the command line?

$ cat test.erl
-module(test).
-export([m/0, g/0]).

m() -> self() ! a, self() ! b.
g() -> receive X -> X after 100 -> timeout end.

Bad behavior ("a" is received, but not "b"):

$ erl
Erlang (BEAM) emulator version 5.6.2 [source] [async-threads:0]  
[kernel-poll:false]

Eshell V5.6.2  (abort with ^G)
1> test:m().
b
2> receive X -> X after 100 -> timeout end.
a
3> receive X -> X after 100 -> timeout end.
timeout
4>

Good behavior (both messages are received):

$ erl
Erlang (BEAM) emulator version 5.6.2 [source] [async-threads:0]  
[kernel-poll:false]

Eshell V5.6.2  (abort with ^G)
1> test:m().
b
2> test:g().
a
3> test:g().
b
4> test:g().
timeout
5>

	Steven




More information about the erlang-questions mailing list