我想知道我的所有衍生进程是否处于空闲状态或者没有做任何事情。所以我有这个特殊的例子,产生了proc/3
proc(A,B,C) ->
receive
{do} ->
NewA = % doing something
NewB = % doing something
NewC = % doing something
% doing something
% ...
io:format("Process: ~w is done doing something.", [self()]),
proc(NewA,NewB,NewC)
end
并[d 0.33.0>,< 0.34.0>,< 0.35.0>,< 0.36.0> ...< 0.1032.0>]
现在,每个进程都会收到一条消息{do}
,告诉他们与其他进程同时执行其下的语句。我怎么知道所有过程是否已完成执行或只是他们现在处于空闲状态?
答案 0 :(得分:2)
我遇到了这个问题,我通过向负责发送do消息的进程发回消息解决了这个问题。在我的情况下,我只需要计算答案的数量。
proc(A,B,C,From) ->
receive
{do} ->
NewA = % doing something
NewB = % doing something
NewC = % doing something
% doing something
% ...
io:format("Process: ~w is done doing something.", [self()]),
From ! {job_done,self()},
proc(NewA,NewB,NewC,From)
end