Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Thread::Mutex#sleep

mutex.sleep(timeout = nil) → number or nil

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.

When the thread is next woken up, it will attempt to reacquire the lock.

Note that this method can wakeup without explicit Thread#wakeup call. For example, receiving signal and so on.

Returns the slept time in seconds if woken up, or nil if timed out.

See also #owned? #synchronize #locked? #try_lock also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1