End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Thread::Mutex#synchronize
mutex.synchronize { ... } → result of the block
thread_sync.c
View on GitHub ↗
static VALUE
rb_mutex_synchronize_m(VALUE self)
{
if (!rb_block_given_p()) {
rb_raise(rb_eThreadError, "must be called with a block");
}
return rb_mutex_synchronize(self, rb_yield, Qundef);
}
Obtains a lock, runs the block, and releases the lock when the block completes. See the example under Thread::Mutex.