Send Message while processing

Yao Bao free7by@REDACTED
Wed Dec 8 16:12:11 CET 2021


> Hi,
> 
> If process A doing a long work and in the same time process B send message to A , I believe that it will successfully recieve the message in A's mailbox. So mailboxes of processes are processes too? If not how it can save the message while is doing some work?
> 

Hello,

A process cannot do things by itself.
It has some private memory but the CPU is publicly available for other processes.

In Erlang, processes don't share memory, but do share CPU (time-sharing).

If we have one computer which contains only one CPU.
And there are three processes: two living Erlang processes: A and B; one Erlang process (the BEAM).

How BEAM actually works should be different, but the illusion might be something like below:
A is doing some work -> (A is working, B is suspending, BEAM is suspending);
B prepare a message -> (B is working, A is suspending, BEAM is suspending);
B sends a message to A -> (BEAM is working, A is suspending, B is suspending);
A receives a message from B -> (BEAM is working, A is suspending, B is suspending);
A is doing some work -> (A is working, B is suspending, BEAM is suspending);
A take the message out from its mailbox -> (A is working, B is suspending, BEAM is suspending);

Cheers,
Yao


More information about the erlang-questions mailing list