[erlang-questions] confusing message behavior

t ty <>
Wed Oct 22 21:51:02 CEST 2008


After the first 'receive' X is bound to 'a', meaning the second
receive could be viewed as:

receive 'a' -> 'a' after 100 -> timeout end.

Do the following:

1> test:m().
2> receive X -> X after 100 -> timeout end.
3> f(X)
4> receive X -> X after 100 -> timeout end.

t

On Wed, Oct 22, 2008 at 3:20 PM, Steven Grady <> wrote:
> 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
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list