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

27 lines
515 B
Ruby

module Mutant
module Actor
# Sender for messages to acting thread
class Sender
include Adamantium::Flat, Concord.new(:condition_variable, :mutex, :messages)
# Send a message to actor
#
# @param [Object] message
#
# @return [self]
#
# @api private
#
def call(message)
mutex.synchronize do
messages << message
condition_variable.signal
end
self
end
end # Sender
end # Actor
end # Mutant