actorName ! msg
Sender never blocks. No handshake. (Overloading
of CSP notation.)
intvar: actor(z: integer) { val myx: integer = z receive msg { case msg.op = set(x): myx := x case msg.op = get() : msg.sender ! myx } } var a: actor = create intvar(5) // external to the actors
become
become
intvar: actor(z: integer) { val myx: integer = z receive msg { case msg.op = set(x): become create intvar(x) case msg.op = get() : msg.sender ! myx } } var a: actor = create intvar(5) // external to the actors var i: integer = a ! get() // i = 5 a ! set(34) // does not return any value var j: integer = a ! get() // j = 34
become
, the actor a
is still available as a target
for send.
a
knows of no other actors. We can mod the
above to collect msg.sender
as it receives messages.
stackNd: actor(elm: actor, lnk: actor) { receive msg { case msg.op = pop(): if (elm != NIL) { become lnk msg.sender ! elm } case msg.op = push(X): P = create stackNd(elm, lnk) become create stackNd(create itemvar(X), P) } }
--------- --------- --------- --->| 3 | --|--->| 4 | --|--->| NIL|NIL| --------- --------- --------- BECOMES ---------- ------- --------- --->|forwarder|--->| 4 | --|--->| NIL | NIL| ---------- ------- ---------
aux: actor(n: nat, r: actor) { receive msg { case msg.op = nat(k): r ! n * k } } factorial: actor() { receive msg { case msg.op = fac(n, a): if (n = 0) a ! nat(1) else { F = create aux(n, a) self ! fac(n - 1, F) } } }
as of 2009
SALSA | Scala | Kilim | AArch | JavAct | Foundry | JetL | |
State Encap | Yes | No | No | Yes | Yes | Yes | Yes |
Safe Message | Yes | No | No | Yes | No | Yes | No |
Fair Sched | Yes | Yes | No | Yes | No | Yes | No |
Loc Transpar | Yes | No | No | Yes | Yes | Yes | Yes |
Mobility | Yes | No | No | Yes | Yes | Yes | No |
(v1.1.2) | (v2.7.3) | (v0.6) | (v0.1.3) | (v1.5.3) | (v1.0) | (v0.1.7) |
A program written in the Scala Actors shows violation of state encapsulation which may cause two actors to simultaneously execute the critical section.
object semaphorenotok { class SemaphoreActor() extends Actor { ... def enter() { if (num < MAX) { // critical section num = num + 1; }} } def main(args: Array[String]): Unit = { var gate = new SemaphoreActor() gate.start gate ! "enter" gate.enter } }
A program written in the Scala Actors showing an Actor "busy-waiting" for a reply. In the absence of fair scheduling, such an actor can potentially starve other actors. [Figure 3 ref1]
object fairness { class FairActor() extends Actor { ... def act() { loop { react { case (v : int) => { data = v } case ("wait") => { // busy-waiting section if (data > 0) println(data) else self ! "wait" } case ("start") => { calc ! ("add", 4, 5) self ! "wait" }}} }}}