When studying carefully “gproc” project’s gproc_tests.erl file. I have found the following code.
The “goodbye” message is send before “erlang:monitor/2”, I think it is possible that ‘DOWN’ message won’t be received. Is it correct? If so, the two lines should be switched, right?
t_simple_aggr_counter() ->
?assert(gproc:reg({c,l,c1}, 3) =:= true),
?assert(gproc:reg({a,l,c1}) =:= true),
?assert(gproc:get_value({a,l,c1}) =:= 3),
P = self(),
P1 = spawn_link(fun() ->
gproc:reg({c,l,c1}, 5),
P ! {self(), ok},
receive
{P, goodbye} -> ok
end
end),
receive {P1, ok} -> ok end,
?assert(gproc:get_value({a,l,c1}) =:= 8),
?assert(gproc:update_counter({c,l,c1}, 4) =:= 7),
?assert(gproc:get_value({a,l,c1}) =:= 12),
P1 ! {self(), goodbye}, %<<===========This line
R = erlang:monitor(process, P1), %<<======This line
receive {'DOWN', R, _, _, _} ->
gproc:audit_process(P1)
end,
?assert(gproc:get_value({a,l,c1}) =:= 7).
the erlang:monitor/2 call will still generate a {‘DOWN’, …} message to the calling process even if the monitored process has already died.
for example: