This page is no longer maintained — Please continue to the home page at www.scala-lang.org

will the actor encounter this situation?

1 reply
Caesar You
Joined: 2009-09-07,
User offline. Last seen 42 years 45 weeks ago.

i define an actor
 
class Actor {
    def act {
        loop
{
            react {
                case msgA => someFunction
            }
        }
    }
}
 
the someFunction is a long task(i call it taskA). so
when it processed by a worker(workerA)
for some CPU time, the worker
assign itself to another task(taskB) in its queue, so taskA
is not running. at the same time, another
worker(workerB) is idle, so it steal taskA.
that means in taskA's liftcycle, it is run by workerA
and workerB.
 

Philipp Haller
Joined: 2009-01-13,
User offline. Last seen 42 years 45 weeks ago.
Re: will the actor encounter this situation?

Caesar You wrote:
> i define an actor
>
> class Actor {
> def act {
> loop {
> react {
> case msgA => someFunction
> }
> }
> }
> }
>
> the someFunction is a long task(i call it taskA). so when it processed
> by a worker(workerA)
> for some CPU time, the worker assign itself to another task(taskB) in
> its queue, so taskA
> is not running. at the same time, another worker(workerB) is idle, so it
> steal taskA.
> that means in taskA's liftcycle, it is run by workerA and workerB.

No, that cannot happen. Once workerA starts executing taskA, taskA can
no longer be stolen by workerB. A task is executed on at most one
worker. But, note that when `react` suspends, the continuation of the
actor is run as part of a new task.

Cheers,
Philipp

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland