Name

Mutex — Mutual exclusion class

Synopsis

This class represents mutually exclusive locks.

Required Library

require ‘thread’

Class Method

Mutex::new

Creates a Mutex object

Instance Methods

m.lock

Locks the Mutex object m.

m.locked?

Returns true if m is locked.

m.synchronize {...}

Locks m and runs the block, then releases the lock when the block exits.

m.try_lock

Attempts to lock m. Returns false if lock fails.

m.unlock

Releases lock on m.

Get Ruby in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.