Skip to main content


Releases a process lock.


UNLOCK expression


expression A number or string, or an expression that evaluates to a number or string specifying an existing lock to be unlocked.


The UNLOCK statement releases a process lock on expression that was obtained by a LOCK statement. Each time a lock is obtained on an expression a lock count is incremented. UNLOCK decrements this count. Only when the lock count falls to zero will the logical lock be released. For this reason, you should balance each successful call to LOCK with a corresponding call to UNLOCK.

Unlike READU locks, process locks set in a program are not released automatically when the program terminates. The lock belongs to the process, and persists for the life of the process, unless unlocked explicitly.

Commonly, expression evaluates to an integer in the range 0 through 64. However, in Caché any number or string may be specified as a logical lock. UNLOCK "" is equivalent to UNLOCK 0.


The following example uses the LOCK statement to obtain a logical lock on an expression, and then uses the UNLOCK function to release the logical lock. Note that because the lock on a was taken twice, it must be unlocked twice.

LOCK a THEN PRINT "Got the lock"
  ELSE PRINT "Couldn't get the lock"
LOCK a THEN PRINT "Got the lock again"
  ELSE PRINT "Couldn't get the lock"

See Also

FeedbackOpens in a new tab