instance method start_exclusive

Ruby on Rails edge

Since v5.0.7.2

Available in: v5.0.7.2 v5.1.7 v5.2.8.1 v6.0.6.1 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3.2 v8.0.5.1 v8.1.3.1 edge

Signature

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

purpose key = nil
compatible key = []
no_wait key = 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

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close