class ActiveSupport::Concurrency::ShareLock
def start_exclusive(purpose: nil, compatible: [], no_wait: false)
+purpose+ matching, it is possible to yield only to other
is awaiting a lock, it is not running any other code. With
For many resources, loose upgrades are sufficient: if a thread
less strict, prevents some classes of deadlocks.
+compatible+ list. This allows a "loose" upgrade, which, being
to any other attempt whose +purpose+ appears in this attempt's
waiting for the exclusive lock, it will yield its share (if any)
+purpose+ and +compatible+ work together; while this thread is
has been acquired.
immediately available. Otherwise, returns true after the lock
Returns false if +no_wait+ is set and the lock is not
def start_exclusive(purpose: nil, compatible: [], no_wait: false) synchronize do unless @exclusive_thread == Thread.current if busy_for_exclusive?(purpose) return false if no_wait yield_shares(purpose: purpose, compatible: compatible, block_share: true) do wait_for(:start_exclusive) { busy_for_exclusive?(purpose) } end end @exclusive_thread = Thread.current end @exclusive_depth += 1 true end end