I think you are looking for something similar. It will work on any instance of the object after its launch. This is not ideal, especially where Thread.stop is outside the mutex. In java, waiting on a thread, it displays a monitor.
class Object def wait @waiting_threads = [] unless @waiting_threads @monitor_mutex = Mutex.new unless @monitor_mutex @monitor_mutex.synchronize { @waiting_threads << Thread.current } Thread.stop end def notify if @monitor_mutex and @waiting_threads @monitor_mutex.synchronize { @waiting_threads.delete_at(0).run unless @waiting_threads.empty? } end end def notify_all if @monitor_mutex and @waiting_threads @monitor_mutex.synchronize { @waiting_threads.each {|thread| thread.run} @waiting_threads = [] } end end end
jakrabbit
source share