From d3640222361fa03d13cb0149f0c06fbde87eb4e1 Mon Sep 17 00:00:00 2001 From: Philipp Haller Date: Thu, 1 Oct 2009 09:46:35 +0000 Subject: Fixed thread-visibility issues causing scala-ni... Fixed thread-visibility issues causing scala-nightly-args 387 to fail. --- src/actors/scala/actors/Actor.scala | 1 + src/actors/scala/actors/Reactor.scala | 7 +++++++ src/actors/scala/actors/ReplyReactor.scala | 1 + 3 files changed, 9 insertions(+) (limited to 'src/actors') diff --git a/src/actors/scala/actors/Actor.scala b/src/actors/scala/actors/Actor.scala index 26b4661170..057436a514 100644 --- a/src/actors/scala/actors/Actor.scala +++ b/src/actors/scala/actors/Actor.scala @@ -390,6 +390,7 @@ trait Actor extends AbstractActor with ReplyReactor with ReplyableActor { * the invocation of send to the place where the thread of * the receiving actor resumes inside receive/receiveWithin. */ + @volatile private var received: Option[Any] = None /* This option holds a TimerTask when the actor waits in a diff --git a/src/actors/scala/actors/Reactor.scala b/src/actors/scala/actors/Reactor.scala index 63c9ff32bd..a3e44d4d2c 100644 --- a/src/actors/scala/actors/Reactor.scala +++ b/src/actors/scala/actors/Reactor.scala @@ -27,6 +27,7 @@ trait Reactor extends OutputChannel[Any] { /* If the actor waits in a react, continuation holds the * message handler that react was called with. */ + @volatile private[actors] var continuation: PartialFunction[Any, Unit] = null /* Whenever this Actor executes on some thread, waitingFor is @@ -37,6 +38,8 @@ trait Reactor extends OutputChannel[Any] { * thread. */ private[actors] val waitingForNone = (m: Any) => false + + // guarded by lock of this private[actors] var waitingFor: Any => Boolean = waitingForNone /** @@ -82,6 +85,9 @@ trait Reactor extends OutputChannel[Any] { private[actors] def makeReaction(fun: () => Unit): Runnable = new ReactorTask(this, fun) + /* Note that this method is called without holding a lock. + * Therefore, to read an up-to-date continuation, it must be @volatile. + */ private[actors] def resumeReceiver(item: (Any, OutputChannel[Any]), onSameThread: Boolean) { // assert continuation != null if (onSameThread) @@ -166,6 +172,7 @@ trait Reactor extends OutputChannel[Any] { * built on top of `seq`. Note that the only invocation of * `kill` is supposed to be inside `Reaction.run`. */ + @volatile private[actors] var kill: () => Unit = () => { exit() } diff --git a/src/actors/scala/actors/ReplyReactor.scala b/src/actors/scala/actors/ReplyReactor.scala index 9e59c4956d..db7a74aba5 100644 --- a/src/actors/scala/actors/ReplyReactor.scala +++ b/src/actors/scala/actors/ReplyReactor.scala @@ -24,6 +24,7 @@ trait ReplyReactor extends Reactor { /* A list of the current senders. The head of the list is * the sender of the message that was received last. */ + @volatile private[actors] var senders: List[OutputChannel[Any]] = Nil -- cgit v1.2.3