method
start_exclusive
v7.1.3.4 -
Show latest stable
- Class:
ActiveSupport::Concurrency::ShareLock
start_exclusive(purpose: nil, compatible: [], no_wait: false)public
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 thread 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 a thread is awaiting a lock, it is not running any other code. With purpose matching, it is possible to yield only to other threads whose activity will not interfere.