Skip to main content

LOCK with Arguments

LOCK with Arguments

LOCK with arguments specifies one or more lock names on which to perform locking and unlocking operations. What lock operation InterSystems IRIS performs depends on the lock operation indicator argument you use:

  • LOCK lockname unlocks all locks previously held by the process in all namespaces, then applies a lock on the specified lock name(s).

  • LOCK +lockname applies a lock on the specified lock name(s) without unlocking any previous locks. This allows you to accumulate different locks, and allows you to apply incremental locks to the same lock.

  • LOCK -lockname performs an unlock operation on the specified lock name(s). Unlocking decrements the lock count for the specified lock name; when this lock count decrements to zero, the lock is released.

A lock operation may immediately apply the lock, or it may place the lock request on a wait queue pending the release of a conflicting lock by another process. A waiting lock request may time out (if you specify a timeout) or may wait indefinitely (until the end of the process).

LOCK with Multiple Lock Names

You can specify multiple locks with a single LOCK command in either of two ways:

  • Without Parentheses: By specifying multiple lock arguments without parentheses as a comma-separated list, you can specify multiple independent lock operations, each of which can have its own timeout. (This is functionally identical to specifying a separate LOCK command for each lock argument.) Lock operations are performed in strict left-to-right order. For example:

      LOCK var1(1):10,+var2(1):15

    Multiple lock arguments without parentheses each can have their own lock operation indicator and their own timeout argument. However, if you use multiple lock arguments, be aware that a lock operation without a plus sign lock operation indicator unlocks all prior locks, including locks applied by an earlier part of the same LOCK command. For example, the command LOCK ^b(1,1), ^c(1,2,3), ^d(1) would be parsed as three separate lock commands: the first releasing the processes’ previously held locks (if any) and locking ^b(1,1), the second immediately releasing ^b(1,1) and locking ^c(1,2,3), the third immediately releasing ^c(1,2,3) locking ^d(1). As a result, only ^d(1) would be locked.

  • With Parentheses: By enclosing a comma-separated list of lock names in parentheses, you can perform these locking operations on multiple locks as a single atomic operation. For example:

      LOCK +(var1(1),var2(1)):10

    All lock operations in a parentheses-enclosed list are governed by a single lock operation indicator and a single timeout argument; either all of the locks are applied or none of them are applied. A parentheses-enclosed list without a plus sign lock operation indicator unlocks all prior locks then locks all of the listed lock names.

The maximum number of lock names in a single LOCK command is limited by several factors. One of them is the number of argument stacks available to a process: 512. Each lock reference requires 4 argument stacks, plus 1 additional argument stack for each subscript level. Therefore, if the lock references have no subscripts, the maximum number of lock names is 127. If the locks have one subscript level, the maximum number of lock names is 101. This should be taken as a rough guide; other factors may further limit the number of locks names in a single LOCK. There is no separate limit on number of locks for a remote system.

FeedbackOpens in a new tab