Erlang messaging architecture

In erlang, if two processes A and B simultaneously send a message to process C. Will there be a race condition?

  • C! {very large message} sent to A
  • C! {very large message} sent B

Will C receive the full message from A and then jump to the message from B? or is it possible that C is likely to receive chunks of message A along with chunks of message B?

+3


source to share


1 answer


Receiving a message is an atomic operation.

If you're wondering how this is done, read the source code for the virtual machine. If I simplify this, the submission process follows these steps:



  • Allocate target memory space during the dispatch process (this is called the environment).
  • Copy message to this memory space
  • Take external lock on target process
  • Link to a message in the list of linked mailboxes
  • Release the external lock on the target process.

As you can see, copying is done outside (before) the critical section, and the critical section is pretty fast. It's just juggling a few pointers.

+5


source







All Articles