[erlang-questions] Message order and exit(Reason)

Richard Carlsson <>
Mon Jan 28 10:58:32 CET 2013


The only place I seem to find this actually described is in the old 
(never finished) Standard Erlang Specification Draft by Barklund and 
Virding. In brief, Thomas is right: with regards to propagation and 
order, exit messages are handled like regular messages. In fact, both 
are instances of what the spec calls Signals, and the ordering 
guarantees are valid for all Signals, not just messages. The spec lists 
the following signals:

   Messages
   Exit signals
   Link requests
   Unlink requests
   Group leader request
   Info request
   Suspend/resume request
   Trace/notrace request

since the spec is quite old, it is possible that there are now other 
examples of signals in the system, or that some of the above are 
obsolete. But the ordering guarantees means that the following code will 
work as expected:

      link(PidA),
      PidA ! 'msg',
      exit(reason).

that is, the link will be set up before 'msg' arrives, and the exit 
signal will arrive after the message.

     /Richard

On 2013-01-28 10:24 , Thomas Lindgren wrote:
>
> Hi Dmitrii,
>
> I think the following means that if A sends M1, M2 to B, then B will
> receive M1, M2 in the order of sending. It's not explicitly stated that
> exit messages are handled the same way as regular messages, though I
> think the default assumption should be that they are. Those here who
> have worked on model checking and whatnot, feel free to expound.
>
>
>       10.8  Is the order of message reception guaranteed?
>
> Yes, but only within one process.
> If there is a live process and you send it message A and then message B,
> it's guaranteed that if message B arrived, message A arrived before it.
> On the other hand, imagine processes P, Q and R. P sends message A to Q,
> and then message B to R. There is no guarantee that A arrives before B.
> (Distributed Erlang would have a pretty tough time if this was required!)
>
> http://www.erlang.org/faq/academic.html
>
> Best,
> Thomas
>
>     ------------------------------------------------------------------------
>     *From:* Dmitrii Dimandt <>
>     *To:* Erlang Questions <>
>     *Sent:* Monday, January 28, 2013 10:00 AM
>     *Subject:* [erlang-questions] Message order and exit(Reason)
>
>     Hi all,
>
>     We've had a semi-heated discussion in Russian community over this
>     question: http://stackoverflow.com/questions/14556109/race-condition-between-trap-exit-exit-msg-and-common-msg
>
>     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.
>
>
>     Can anyone with the intimate knowledge of Erlang internals shed some
>     light on this?
>
>     Thanks!
>
>     _______________________________________________
>     erlang-questions mailing list
>      <mailto:>
>     http://erlang.org/mailman/listinfo/erlang-questions
>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>




More information about the erlang-questions mailing list