- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
will the actor encounter this situation?
Fri, 2009-12-04, 09:36
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.
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