Actor model and process calculi
In computer science, the Actor model and process calculi are two closely related approaches to the modelling of concurrent digital computation. See Actor model and process calculi history.
There are many similarities between the two approaches, but also several differences :
- There is only one Actor model ; there are numerous process calculi, developed for reasoning about a variety of different kinds of concurrent systems at various levels of detail.
- The Actor model was inspired by the laws of physics and depends on them for its fundamental axioms, i.e. physical laws ; the process calculi were originally inspired by algebra.
- Processes in the process calculi are anonymous, and communicate by sending messages either through named channels, or via ambients. In contrast, actors in the Actor model possess an identity, and communicate by sending messages to the mailing addresses of other actors.
How do channels work?
Indirect communication using channels has been an important issue for communication in parallel and concurrent computation affecting both semantics and performance. Some process calculi differ from the Actor model in their use of channels as opposed to direct communication.Synchronous channels
Synchronous channels have the property that a sender putting a message in the channel must wait for a receiver to get the message out of the channel before the sender can proceed.Simple synchronous channels
A synchronous channel can be modeled by an Actor that receivesput
and get
communications. The following is the behavior of an Actor for a simple synchronous channel:- Each
put
communication has a message and an address to which an acknowledgment is sent when the message is received by aget
communication from the channel in FIFO order. - Each
get
communication has an address to which the received message is sent.Synchronous channels in process calculi
put
and get
messages; however at most one of the guards can be chosen for each execution of the guarded choice command. Because only one guard can be chosen, a guarded choice command in general effectively requires a kind of two-phase commit protocol or perhaps even a three-phase commit protocol if time-outs are allowed in guards.Consider the following program written in CSP :
||
Z :: n: integer; n:= 0;
* Y?go → n := n+1; Y!true]
]
According to Clinger , this program illustrates global nondeterminism, since the nondeterminism arises from incomplete specification of the timing of signals between the three processes
X
, Y
, and Z
. The repetitive guarded command in the definition of Z
has two alternatives: - the
stop
message is accepted fromX
, in which caseY
is sent the value false andprint
is sent the valuen
- a
go
message is accepted fromY
, in which casen
is incremented andY
is sent the value true.
Z
ever accepts the stop
message from X
, then X
terminates. Accepting the stop
causes Y
to be sent false which when input as the value of its guard will cause Y
to terminate. When both X
and Y
have terminated, Z
terminates because it no longer has live processes providing input.In the above program, there are synchronous channels from
X
to Z
, Y
to Z
, and Z
to Y
.Analogy with the committee coordination problem
According to Knabe , Chandy and Misra characterized this as analogous to the committee coordination problem:A simple distributed protocol
This section presents a simple distributed protocol for channels in synchronous process calculi. The protocol has some problems that are addressed in the sections below.The behavior of a guarded choice command is as follows:
- The command sends a message to each of its guards to
prepare
. - When it receives the first response from one of its guards that it is prepared, then it sends a message to that guard to
prepare to commit
and sends messages to all of the other guards toabort
. - *When it receives a message from the guard that it is
prepared to commit
, then it sends the guard acommit
message. However, if the guard throws an exception that it cannotprepare to commit
, then guarded choice command starts the whole process all over again. - If all of its guards respond that they cannot
prepare
, then the guarded command does nothing.
- When a message to
prepare
is received, then the guard sends aprepare
message to each of the channels with which it is offering to communicate. If the guard has booleans such that it cannotprepare
or if any of the channels respond that they cannotprepare
, then it sendsabort
messages to the other channels and then responds that it cannotprepare
. - *When a message to
prepare to commit
is received, then the guard sends aprepare to commit
message to each of the channels. If any of the channels respond that they cannotprepare to commit
, then it sendsabort
messages to the other channels and then throws an exception that it cannotprepare to commit
. - *When a message to
commit
is received, then the guard sends ancommit
message to each of the channels. - *When a message to
abort
is received, then the guard sends anabort
message to each of the channels.
- When a
prepare to put
communication is received, then respond that it is prepared if there is aprepare to get
communication pending unless aterminate
communication has been received, in which case throw an exception that it cannotprepare to put
. - When a
prepare to get
communication is received, then respond that it is prepared if there is aprepare to put
communication pending unless aterminate
communication has been received, in which case throw an exception that it cannotprepare to get
. - *When a
prepare to commit to put
communication is received, then respond that it is prepared if there is aprepare to commit to get
communication pending unless aterminate
communication has been received, in which case throw an exception that it cannotprepare to commit to put
. - *When a
prepare to commit to get
communication is received, then respond that it is prepared if there is aprepare to commit to put
communication pending unless aterminate
communication has been received, in which case throw an exception that it cannotprepare to commit to get
. - **When a
commit put
communication is received, then depending on which of the following is received: - ***When a
commit get
communication is received, then if not already done perform theput
andget
and clean up the preparations. - ***When an
abort get
communication is received, then cancel the preparations - **When a
commit get
communication is received, then depending on which of the following is received: - ***When a
commit put
communication is received, then if not already done perform theget
andput
and clean up the preparations. - ***When an
abort put
communication is received, then cancel the preparations. - **When an
abort put
communication is received, then cancel the preparations. - **When an
abort get
communication is received, then cancel the preparations.Starvation on getting from multiple channels
||
Z :: n: integer; n:= 0;
* Y?go → n := n+1; Y!true]
]
As pointed out in Knabe , a problem with the above protocol is that the process
Z
might never accept the stop
message from X
and consequently the above program might never print anything.In contrast consider, a simple Actor system that consists of Actors X, Y, Z, and print where
- the Actor X is created with the following behavior:
- *If the message
"start"
is received, then send Z the message"stop"
- the Actor Y is created with the following behavior:
- *If the message
"start"
is received, then send Z the message"go"
- *If the message true is received, then send Z the message
"go"
- *If the message false is received, then do nothing
- the Actor Z is created with the following behavior that has a count
n
that is initially 0: - *If the message
"start"
is received, then do nothing. - *If the message
"stop"
is received, then send Y the message false and send print the message the countn
. - *If the message
"go"
is received, then send Y the message true and process the next message received with countn
beingn+1
.
"start"
message resulting in sending print a number that can be unbounded large.The difference between the CSP program and the Actor system is that the Actor Z does not get messages using a guarded choice command from multiple channels. Instead it processes messages in arrival ordering, and by the laws for Actor systems, the
stop
message is guaranteed to arrive.Livelock on getting from multiple channels
Consider the following program written in CSP :Bids2?b → process1!b;] ||
Bidder2 :: b: bid;
* Bids2?b → process2!b;]
]
As pointed out in Knabe , an issue with the above protocol is that the process
Bidder2
might never accept a bid from Bid1
or Bid2
and consequently process2
might never be sent anything. In each attempt to accept a message, Bidder2
is thwarted because the bid that was offered by Bids1
or Bids2
is snatched away by Bidder1
because it turns out that Bidder1
has much faster access than Bidder2
to Bids1
and Bids2
. Consequently, Bidder1
can accept a bid, process it and accept another bid before Bidder2
can commit to accepting a bid.Efficiency
As pointed out in Knabe , an issue with the above protocol is the large number of communications that must be sent in order to perform the handshaking in order to send a message through a synchronous channel. Indeed, as shown in the previous section, the number of communications can be unbounded.Summary of Issues
The subsections above have articulated the following three issues concerned with the use of synchronous channels for process calculi:- Starvation. The use of synchronous channels can cause starvation when a process attempts to get messages from multiple channels in a guarded choice command.
- Livelock. The use of synchronous channels can cause a process to be caught in livelock when it attempts to get messages from multiple channels in a guarded choice command.
- Efficiency. The use of synchronous channels can require a large number of communications in order to get messages from multiple channels in a guarded choice command.
Asynchronous channels
Asynchronous channels have the property that a sender putting a message in the channel need not wait for a receiver to get the message out of the channel.Simple asynchronous channels
An asynchronous channel can be modeled by an Actor that receivesput
and get
communications. The following is the behavior of an Actor for a simple asynchronous channel:- Each
put
communication has a message and an address to which an acknowledgment is sent immediately. - Each
get
communication has an address to which the gotten message is sent.Asynchronous channels in process calculi
Algebras
The use of algebraic techniques was pioneered in the process calculi. Subsequently, several different process calculi intended to provide algebraic reasoning about Actor systems have been developed in,,Denotational Semantics
Will Clinger published the first satisfactory mathematical denotational theory of the Actor model using domain theory in his dissertation in 1981. His semantics contrasted the unbounded nondeterminism of the Actor model with the bounded nondeterminism of CSP and Concurrent Processes . Roscoe has developed a denotational semantics with unbounded nondeterminism for a subsequent version of Communicating Sequential Processes Hoare . More recently Carl Hewitt developed a denotational semantics for Actors based on timed diagrams.Ugo Montanari and Carolyn Talcott have contributed to attempting to reconcile Actors with process calculi.