free_mutant/lib/mutant/actor/env.rb
Markus Schirp d8e6805206 Fix actor race condition
* Use the `ConditionVariable` primitive to fix rece between stopped
  receiver Thread and its wake signal.
* Race was only observable via synthetical benchmarks and explicit
  sleeps between unlocking receiver mutex and Thread.stop
* Simplifies code a lot as thread must not be passed around anymore
2014-12-06 04:37:20 +00:00

35 lines
577 B
Ruby

module Mutant
module Actor
# Actor root environment
class Env
include Concord.new(:thread_root)
# Spawn a new actor executing block
#
# @return [Actor::Sender]
#
# @api private
#
def spawn
mailbox = new_mailbox
thread_root.new do
yield mailbox
end
mailbox.sender
end
# Return new unbound mailbox
#
# @return [Mailbox]
#
# @api private
#
def new_mailbox
Mailbox.new
end
end # Env
end # Actor
end # Mutant