diff --git a/src/syndicate/actors.nim b/src/syndicate/actors.nim index 198d63a..20d3c51 100644 --- a/src/syndicate/actors.nim +++ b/src/syndicate/actors.nim @@ -43,7 +43,9 @@ type future: Future[void] name: string id: ActorId - handleAllocator: Handle + handleAllocator: ref Handle + # a fresh actor gets a new ref Handle and + # all actors spawned from it get the same ref. root: Facet exitReason: ref Exception exitHooks: seq[TurnAction] @@ -119,8 +121,8 @@ proc hash*(facet): Hash = proc hash*(r: Ref): Hash = !$(r.relay.hash !& r.target.unsafeAddr.hash) proc nextHandle(facet: Facet): Handle = - inc facet.actor.handleAllocator - facet.actor.handleAllocator + result = succ(facet.actor.handleAllocator[]) + facet.actor.handleAllocator[] = result proc facet*(turn: var Turn): Facet = turn.facet @@ -382,6 +384,7 @@ proc newActor(name: string; bootProc: TurnAction; initialAssertions: OutboundTab result = Actor( name: name, id: ActorId(seed)) + new result.handleAllocator result.root = newFacet(result, none Facet) result.future = newFuture[void]($result) run( @@ -397,7 +400,8 @@ proc spawn*(name: string; turn: var Turn; bootProc: TurnAction; initialAssertion var newOutBound: Table[Handle, OutboundAssertion] for key in initialAssertions: discard turn.facet.outbound.pop(key, newOutbound[key]) - discard newActor(name, bootProc, newOutBound) + let actor = newActor(name, bootProc, newOutBound) + actor.handleAllocator = turn.facet.actor.handleAllocator proc newInertRef*(): Ref = let a = bootActor("inert") do (turn: var Turn): turn.stop()