free_mutant/lib/mutant/actor/mailbox.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

38 lines
811 B
Ruby

module Mutant
module Actor
# Unbound mailbox
class Mailbox
include Adamantium::Flat, Concord::Public.new(:receiver, :sender)
# Return new mailbox
#
# @return [Mailbox]
#
# @api private
#
def self.new
mutex = Mutex.new
condition_variable = ConditionVariable.new
messages = []
super(
Receiver.new(condition_variable, mutex, messages),
Sender.new(condition_variable, mutex, messages)
)
end
# Return binding for RPC to other actors
#
# @param [Actor::Sender] other
#
# @return [Binding]
#
# @api private
#
def bind(other)
Binding.new(self, other)
end
end # Mailbox
end # Actor
end # Mutant