Synchronizing Access to an Object : Synchronization « Threads « Ruby






Synchronizing Access to an Object


require 'thread'
class Object
  def synchronize
    mutex.synchronize { yield self }
  end

  def mutex
    @mutex ||= Mutex.new
  end
end

 








Related examples in the same category

1.Multithreads without synchronization
2.Controlling the Thread Scheduler
3.This is easy using monitors.
4.Use monitor to lock
5.make specific objects into monitors.