UNLOCK

UNLOCK

Top  Previous  Next

 

The UNLOCK statement releases one of 64 system wide task locks.

 

 

Format

 

UNLOCK {lock.num} {THEN statement(s)} {ELSE statement(s)}

 

where

 

lock.numevaluates to the lock number in the range 0 to 63. If omitted or specified as a negative value, all task locks owned by the process will be released.

 

statement(s)are statements to be executed depending on the outcome of the UNLOCK operation.

 

The THEN and ELSE clauses are both optional.

 

 

The UNLOCK statement releases the specified task lock if it has previously been acquired using the LOCK statement. There is no means for a program to determine which task locks are held by the user except by attempting to lock each in turn and checking the STATUS() value. Beware that unlike read, update and file locks, task locks are only automatically released on leaving QM, not on return to the command prompt.

 

When lock.num is omitted or evaluates to a negative number, all task locks owned by the process are released. This action is always successful, even if no locks are owned.

 

The THEN clause is executed if the lock is held by this process. The value of the STATUS() function will be zero.

 

The ELSE clause is executed if the lock is not owned by this process. The value of the STATUS() function will be ER$LCK if the lock is owned by another process or ER$NLK if it is not owned by any process.

 

 

Example

 

LOCK 7 THEN

  ...processing statements...

  UNLOCK 7

END

ELSE ABORT "Cannot obtain task lock"

 

This program fragment obtains task lock 7, performs some critical processing and then releases the lock.

 

 
See also:

CLEAR.LOCKS, LIST.LOCKS, LOCK (Command), LOCK (QMBasic), TESTLOCK()