diff --git a/akka-actor/src/main/scala/akka/dispatch/MessageHandling.scala b/akka-actor/src/main/scala/akka/dispatch/MessageHandling.scala index 36782d9712..c8af167d2c 100644 --- a/akka-actor/src/main/scala/akka/dispatch/MessageHandling.scala +++ b/akka-actor/src/main/scala/akka/dispatch/MessageHandling.scala @@ -72,19 +72,22 @@ abstract class MessageDispatcher extends Serializable { /** * Attaches the specified actor instance to this dispatcher */ - final def attach(actor: ActorInstance) { - guard withGuard { + final def attach(actor: ActorInstance): Unit = { + val promise = new ActorPromise(Timeout.never)(this) + guard.lock.lock() + try { register(actor) - val promise = new ActorPromise(Timeout.never)(this) dispatchMessage(new MessageInvocation(actor, Init, promise)) - promise - }.get + } finally { + guard.lock.unlock() + } + promise.get } /** * Detaches the specified actor instance from this dispatcher */ - final def detach(actor: ActorInstance) { + final def detach(actor: ActorInstance): Unit = { guard withGuard { unregister(actor) }