
* 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
27 lines
515 B
Ruby
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
|