Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Thread::Mutex#synchronize
[X] () { () -> X } -> X
mutex.synchronize { ... } → result of the block
thread_sync.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/thread_sync.rb, line 387
def synchronize
raise ThreadError, "must be called with a block" unless defined?(yield)
Primitive.rb_mut_synchronize
end
Obtains a lock, runs the block, and releases the lock when the block completes. See the example under Thread::Mutex.