monitor message order
Vladimir Sekissov
svg@REDACTED
Sun Sep 21 16:48:42 CEST 2003
Good day,
vances> If I have a process set up multiple monitors to another
vances> process is there any telling which monitor reference will
vances> be returned first? FIFO? FILO? Random?
If I correctly understand source
erts/emulator/beam/erl_process.c
erts/emulator/beam/bif.c
erts/emulator/beam/utils.c
the order is LIFO.
Reference consists from four cyclic counters so we can do simple test:
19> F1 = fun () -> receive stop -> exit(normal) end end.
#Fun<erl_eval.19.280769>
24> F2 = fun (Cont) ->
receive
Msg ->
io:format("~p~n", [Msg]), Cont(Cont)
after 5000 -> ok
end
end.
#Fun<erl_eval.5.123085357>
25> F3 = fun (Pid) ->
lists:foreach(fun (_) -> erlang:monitor(process, Pid) end,
[1,2,3,4,5,6]),
Pid ! stop,
F2(F2)
end.
27> F3(spawn(F1)).
{'DOWN',#Ref<0.0.0.11860>,process,<0.2289.0>,normal}
{'DOWN',#Ref<0.0.0.11859>,process,<0.2289.0>,normal}
{'DOWN',#Ref<0.0.0.11858>,process,<0.2289.0>,normal}
{'DOWN',#Ref<0.0.0.11857>,process,<0.2289.0>,normal}
{'DOWN',#Ref<0.0.0.11856>,process,<0.2289.0>,normal}
{'DOWN',#Ref<0.0.0.11855>,process,<0.2289.0>,normal}
ok
Best Regards,
Vladimir Sekissov
vances>
vances> If I have a process set up multiple monitors to another
vances> process is there any telling which monitor reference will
vances> be returned first? FIFO? FILO? Random?
vances>
vances> I'm trying to keep track of the processes that have created
vances> resources on a server and garbage collect those resources
vances> when the process goes away without cleaning up after itself.
vances>
vances> It's easy enough at first glance but I'm struggling with the
vances> order of operations as there are dependencies on these
vances> resources. If I could be sure of the order of receipt of
vances> the 'DOWN' messages it would greatly simplify things.
vances>
vances> -Vance
More information about the erlang-questions
mailing list