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).
This commit is contained in:
Roland 2011-11-11 20:51:30 +01:00
parent cd5baf8cd9
commit 85e37ea8ef

View file

@ -160,20 +160,21 @@ abstract class ActorRef extends java.lang.Comparable[ActorRef] with Serializable
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
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()
/**