Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Thread::Mutex#synchronize
[X] () { () -> X } -> X
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.