diff options
author | Philipp Haller <hallerp@gmail.com> | 2007-03-05 11:21:12 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2007-03-05 11:21:12 +0000 |
commit | 0d03cad11528942ccdd8917b6d106b1dbb9afa79 (patch) | |
tree | e1fc68d6e47a3649ce896d524686e356bf2c0a85 /src | |
parent | c09dd61567daf1a156e687564581626687023338 (diff) | |
download | scala-0d03cad11528942ccdd8917b6d106b1dbb9afa79.tar.gz scala-0d03cad11528942ccdd8917b6d106b1dbb9afa79.tar.bz2 scala-0d03cad11528942ccdd8917b6d106b1dbb9afa79.zip |
scala.actors: Fixed race in TimerThread
Diffstat (limited to 'src')
-rw-r--r-- | src/actors/scala/actors/Actor.scala | 7 | ||||
-rw-r--r-- | src/actors/scala/actors/TimerThread.scala | 6 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/actors/scala/actors/Actor.scala b/src/actors/scala/actors/Actor.scala index 55bfb662b9..df2ec1571b 100644 --- a/src/actors/scala/actors/Actor.scala +++ b/src/actors/scala/actors/Actor.scala @@ -329,6 +329,9 @@ trait Actor extends OutputChannel[Any] { if (shouldExit) exit() this.synchronized { tick() + // first, remove spurious TIMEOUT message from mailbox if any + val spurious = mailbox.extractFirst((m: Any) => m == TIMEOUT) + val qel = mailbox.extractFirst((m: Any) => f.isDefinedAt(m)) if (null eq qel) { if (msec == 0) { @@ -392,6 +395,9 @@ trait Actor extends OutputChannel[Any] { Scheduler.pendReaction this.synchronized { tick() + // first, remove spurious TIMEOUT message from mailbox if any + val spurious = mailbox.extractFirst((m: Any) => m == TIMEOUT) + val qel = mailbox.extractFirst((m: Any) => f.isDefinedAt(m)) if (null eq qel) { waitingFor = f.isDefinedAt @@ -504,6 +510,7 @@ trait Actor extends OutputChannel[Any] { private[actors] var isDetached = false private[actors] var isWaiting = false + // guarded by lock of this private[actors] def scheduleActor(f: PartialFunction[Any, Unit], msg: Any) = if ((f eq null) && (continuation eq null)) { // do nothing (timeout is handled instead) diff --git a/src/actors/scala/actors/TimerThread.scala b/src/actors/scala/actors/TimerThread.scala index 1c5a65959e..397c489414 100644 --- a/src/actors/scala/actors/TimerThread.scala +++ b/src/actors/scala/actors/TimerThread.scala @@ -70,8 +70,7 @@ object TimerThread extends AnyRef with Runnable { // process guys waiting for signal and empty list for (val wa <- lateList) { if (wa.valid) { - wa.actor.continuation = null - wa.actor.scheduleActor(wa.f, TIMEOUT) + wa.actor ! TIMEOUT } } lateList = Nil @@ -90,8 +89,7 @@ object TimerThread extends AnyRef with Runnable { def requestTimeout(a: Actor, f: PartialFunction[Any, Unit], waitMillis: long): unit = synchronized { val wakeTime = now + waitMillis if (waitMillis <= 0) { - a.continuation = null - a.scheduleActor(f, TIMEOUT) + a ! TIMEOUT return } |