Locks a resource such as a file or system procedure using a predefined mutex.
LOCK MUTEX [ owner.]mutex-name [ IN { SHARE | EXCLUSIVE } MODE ] [ TIMEOUT num-milliseconds ]
The owner of the mutex. owner can also be specified using an indirect identifier (for example, `[@variable-name]`).
The name of the mutex. mutex-name can also be specified using an indirect identifier (for example, `[@variable-name]`).
Use this clause to specify whether the lock provides exclusive access to the resource (EXCLUSIVE), or whether other connections can use the resource as well (SHARE). If the IN...MODE clause is not specified, then EXCLUSIVE is the default behavior.
The amount of time, in milliseconds (greater than 0), to wait to acquire the lock. If the TIMEOUT clause is not specified, then the connection waits indefinitely until the lock can be acquired.
number-milliseconds can be specified using a variable (for example, TIMEOUT @timeout-value). If number-milliseconds is set to a variable and the variable is NULL, the behavior is equivalent to not specifying the clause.
Recursive LOCK MUTEX statements are allowed; however, an equal number of releases (RELEASE MUTEX) are required to release the mutex for connection-scope mutexes.
If a connection executes the LOCK MUTEX statement in SHARE MODE, and then again in EXCLUSIVE MODE, it may be blocked if other connections have the mutex locked in SHARE MODE. If not, then then the lock mode changes to an exclusive lock and remains that way until the lock is completely released by the connection.
For transaction-scope mutexes (that is, the SCOPE TRANSACTION clause was specified at creation time), the mutex is held until the end of the transaction. For connection-scope mutexes (that is, the SCOPE CONNECTION clause was specified at creation time), the mutex is held until a RELEASE MUTEX statement is execute, or the connection is terminated.
LOCK MUTEX statements benefit from the same deadlock detection used for table and row locks.
You must have the UPDATE ANY MUTEX SEMAPHORE system privilege, or be the owner of the mutex.
None.
Not in the standard.
The following statement locks the protect_my_cr_section mutex in exclusive mode:
LOCK MUTEX protect_my_cr_section IN EXCLUSIVE MODE;