Class Mutex
In: thread.c
Parent: 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
    }
  }

Methods

lock   locked?   new   sleep   try_lock   unlock  

Public Class methods

Public Instance methods

Attempts to grab the lock and waits if it isn‘t available. Raises ThreadError if mutex was locked by the current thread.

Returns true if this lock is currently held by some thread.

Releases the lock and sleeps timeout seconds if it is given and non-nil or forever. Raises ThreadError if mutex wasn‘t locked by the current thread.

Attempts to obtain the lock and returns immediately. Returns true if the lock was granted.

Releases the lock. Raises ThreadError if mutex wasn‘t locked by the current thread.

[Validate]

ruby-doc.org is a service of James Britt and Happy Camper Studios, a Ruby application development company in Phoenix, AZ.

Documentation content on ruby-doc.org is provided by remarkable members of the Ruby community.

For more information on the Ruby programming language, visit ruby-lang.org.

Want to help improve Ruby's API docs? See Ruby Documentation Guidelines.