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
thread_sync.c
View on GitHub ↗
static VALUE
mutex_sleep(int argc, VALUE *argv, VALUE self)
{
VALUE timeout;
timeout = rb_check_arity(argc, 0, 1) ? argv[0] : Qnil;
return rb_mutex_sleep(self, timeout);
}
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.