Everything we’ve learned about sequential programming is still true
for concurrent programming. All we have to do is to add the following
primitives:
Pid = spawn(Fun)
Pid ! Message
receive … end
Pid = spawn(Fun)
Creates a new concurrent process that evaluates Fun. The new
process runs in parallel with the caller. spawn returns a Pid (short
for process identifier). You can use Pid to send messages to the
process.
Pid ! Message
Sends Message to the process with identifier Pid. Message sending
is asynchronous. The sender does not wait but continues with
what it was doing. ! is called the send operator.
Pid ! M is defined to be M—the message sending primitive ! returns
the message itself. Because of this, Pid1 ! Pid2 ! … ! M means send
the message M to all the processes Pid1, Pid2, and so on.
receive … end
Receives a message that has been sent to a process. It has the following skeleton :
receive
_ ->
ok
end.
To be continue with simple example …


