class

Mutex

v1_9_3_125 - Show latest stable - Superclass: Object

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
  }
}

Files

  • prelude.rb
  • thread.c

1Note

See also ConditionVariable

stevecj ยท Dec 9, 2014

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.