From 85e37ea8efddac31c4b58028e5e73589abce82d8 Mon Sep 17 00:00:00 2001 From: Roland Date: Fri, 11 Nov 2011 20:51:30 +0100 Subject: [PATCH] fix one safe publication issue (don't get your hopes up just yet: ActorPoolSpec still failing) The issue was that during the LocalActorRef constructor 'this' was published via the ActorCell's start method. The JMM's visibility guarantee for final fields is only valid after the constructor returned, thus I introduced a store-load barrier before calling ActorCell.start by making actorCell a @volatile var (not sure what @volatile val means). That way every user of the ActorRef reads the volatile field before anything else, ensuring proper publication of the whole LocalActorRef/ActorCell conglomerate (where the latter has quite a lot of non-final fields). --- akka-actor/src/main/scala/akka/actor/ActorRef.scala | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/akka-actor/src/main/scala/akka/actor/ActorRef.scala b/akka-actor/src/main/scala/akka/actor/ActorRef.scala index f71ef0c9a4..3c8dd0bacc 100644 --- a/akka-actor/src/main/scala/akka/actor/ActorRef.scala +++ b/akka-actor/src/main/scala/akka/actor/ActorRef.scala @@ -160,20 +160,21 @@ abstract class ActorRef extends java.lang.Comparable[ActorRef] with Serializable * @author Jonas Bonér */ class LocalActorRef private[akka] ( - _app: ActorSystem, - props: Props, + app: ActorSystem, + _props: Props, _supervisor: ActorRef, val path: ActorPath, val systemService: Boolean = false, - receiveTimeout: Option[Long] = None, - hotswap: Stack[PartialFunction[Any, Unit]] = Props.noHotSwap) + _receiveTimeout: Option[Long] = None, + _hotswap: Stack[PartialFunction[Any, Unit]] = Props.noHotSwap) extends ActorRef with ScalaActorRef { def name = path.name - def address: String = _app.address + path.toString + def address: String = app.address + path.toString - private[this] val actorCell = new ActorCell(_app, this, props, _supervisor, receiveTimeout, hotswap) + @volatile + private var actorCell = new ActorCell(app, this, _props, _supervisor, _receiveTimeout, _hotswap) actorCell.start() /**