【发布时间】:2022-01-09 14:31:37
【问题描述】:
看过一篇关于erlang select接收机制的文章,文章最后有一个结论:“消息从邮箱移动到保存队列,匹配的消息到达后再返回邮箱” .我已经尝试了文章中显示的示例,但我无法得到相同的结果。这是我的代码,我的 erlang/otp 版本是 21。
shell1:
(aaa@HW0003727)1> register(shell, self()).
true
(aaa@HW0003727)2> shell ! c, shell ! d.
d
(aaa@HW0003727)3> process_info(whereis(shell),messages).
{messages,[c,d]}.
(aaa@HW0003727)4> receive a -> 1; b -> 2 end.
shell2:
(aaa@HW0003727)1> process_info(whereis(shell),messages).
{messages,[c,d]}
(aaa@HW0003727)2> process_info(whereis(shell)).
[{registered_name,shell},
{current_function,{prim_eval,'receive',2}},
{initial_call,{erlang,apply,2}},
{status,waiting},
{message_queue_len,2},
{links,[<0.113.0>]},
{dictionary,[]},
{trap_exit,false},
{error_handler,error_handler},
{priority,normal},
{group_leader,<0.112.0>},
{total_heap_size,4212},
{heap_size,1598},
{stack_size,30},
{reductions,13906},
{garbage_collection,[{max_heap_size,#{error_logger => true,kill => true,size => 0}},
{min_bin_vheap_size,46422},
{min_heap_size,233},
{fullsweep_after,65535},
{minor_gcs,1}]},
{suspending,[]}]
文章链接:https://blog.ndpar.com/2010/11/10/erlang-selective-receive/
【问题讨论】:
标签: erlang erlang-otp erlang-shell