[erlang-questions] Questions about processes and message queues

Dominic Williams <>
Wed Feb 4 16:13:05 CET 2009


Hello again Nicola,

I suggested:

> Have you tried to see what happens if a process sends itself
> messages and never reads them? In the shell:
>
> 1> F = fun (G) -> self() ! hello, G(G) end.

This version crashes the VM a lot faster, because the messages
get bigger and bigger:

1> Fun = fun (M, F) -> F (self () ! [M | M], F) end.
#Fun<erl_eval.12.113037538>
2> Report = fun (Pid, R) -> io: fwrite ("~p~n", [erlang: process_info
(Pid, [memory, message_queue_len])]), timer: sleep (5000), R(Pid, R) end.
#Fun<erl_eval.12.113037538>
3> Report (spawn (fun () -> Fun ("hello", Fun) end), Report).
[{memory,1892},{message_queue_len,0}]
[{memory,3174684},{message_queue_len,107349}]
[{memory,6921076},{message_queue_len,194185}]
...

Regards,

Dominic Williams
http://dominicwilliams.net




More information about the erlang-questions mailing list