instance method
start_exclusive
Ruby on Rails edge
Since v5.0.7.2Signature
start_exclusive(purpose: nil, compatible: [], no_wait: false)
Returns false if no_wait is set and the lock is not immediately available. Otherwise, returns true after the lock has been acquired.
purpose and compatible work together; while this owner is waiting for the exclusive lock, it will yield its share (if any) to any other attempt whose purpose appears in this attempt’s compatible list. This allows a “loose” upgrade, which, being less strict, prevents some classes of deadlocks.
For many resources, loose upgrades are sufficient: if an owner is awaiting a lock, it is not running any other code. With purpose matching, it is possible to yield only to other owners whose activity will not interfere.
Parameters
-
purposekey = nil -
compatiblekey = [] -
no_waitkey = false
Source
# File activesupport/lib/active_support/concurrency/share_lock.rb, line 78
def start_exclusive(purpose: nil, compatible: [], no_wait: false)
synchronize do
unless @exclusive_owner == current_owner
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_owner = current_owner
end
@exclusive_depth += 1
true
end
end
Defined in activesupport/lib/active_support/concurrency/share_lock.rb line 78
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::Concurrency::ShareLock