Flowdock

Mutex implements a simple semaphore that can be used to coordinate access to shared data from multiple concurrent threads.

Example:

  require 'thread'
  semaphore = Mutex.new

  a = Thread.new {
    semaphore.synchronize {
      # access shared resource
    }
  }

  b = Thread.new {
    semaphore.synchronize {
      # access shared resource
    }
  }
Show files where this class is defined (1 file)
Register or log in to add new notes.
December 9, 2014
0 thanks

See also ConditionVariable

If you need to and processing with respect to a particular resource between 2 or more threads in more complicated ways, it is likely that ConditionVariable is what you’re looking for.