Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Race condition between trap_exit EXIT msg and common msg

Tags:

erlang

Hi the question is as following: Assume we have processes A and B which are linked. Process's A flag trap_exit is set to true. Let B process send a msg to A and then exit:

PidA ! 'msg',
exit(reason).

What I wanna know if we can be shure that the process A will receive 'msg' and only after It {'EXIT', Pid, reason} will come ? Can we predict the ordering of msgs? I can't found any proofs in documentation, but I guess that it will work that way, but I need some proofs. Don't want to have race condition here..

like image 352
Def_NulL Avatar asked Jan 28 '13 05:01

Def_NulL


2 Answers

As to not leave this question hanging. This is the discussion in erlang-questions mailing list:

http://thread.gmane.org/gmane.comp.lang.erlang.general/66788

Long story short: all messages are signals (or all signals are messages), exits are seen as messages from the process, guaranteed to arrive in the same order they were sent.

like image 115
Mamut Avatar answered Sep 20 '22 00:09

Mamut


Sounds like a code smell to me. Why do you need to rely on trap_exit? Have you thought of alternatives, e.g. proper monitoring?

like image 24
Tilman Avatar answered Sep 18 '22 00:09

Tilman