Alex Rivera | Logout

How is "become" implemented in languages that support the actor model?

Asked 2010-07-24T13:29:20.780
12

The actor model is nicely described by Gul Agha on his technical report, "Actors: a model of concurrent computation in distributed systems".

On page 49 he explains the "become" command:

become <expression>

After calling "become X", an actor will forward all his messages to another actor's mailbox (X).

I'm not sure, however, how this is implemented (it it's implemented at all) in languages like Erlang and Scala. Is it somethign I have to code manually? What about efficiency? Agha shows an implementation of a stack using message-passing. Every time a pop or push is performed, one more forwarding link is added to some actor... After hundreds of thousands of operations, I'd expect such an implementation to spend too much time forwarding messages and not doing actual work, unless some nice optimizations were performed under the hood.

So my question is: how is forwarding (or "become") implemented in typical actor languages like Erlang, Scala (and libraries for other languages)?

Edit
Report

1 Answer

4

Actor is a contravariant cofunctor, so "become" is just comap.

Put another way, an Actor on messages of type T is basically a function of type (T => Unit). And this is simply function composition (with the identity function, perhaps).

It is implemented in Scalaz:

val a1 = actor(a => println(a))
val a2 = a1.comap(f)

The actor a2 applies f to its messages and then sends the result to a1.

answered 2010-07-24T23:12:33.277

Your Answer