LOCK

LOCK

Top  Previous  Next

 

The LOCK command sets a task lock.

 

 

Format

 

LOCK lock.number {NO.WAIT}

 

where

 

lock.numberis the number of the task lock (0 to 63) to be set.

 

NO.WAITspecifies that the process is not to wait if the lock is not available.

 

 

The LOCK command sets one of the 64 system wide task locks. Four situations exist:

 

If the lock is available, the process acquires the lock and continues. @SYSTEM.RETURN.CODE will be set to lock.number.

 

If the lock is already owned by this process, a warning message is displayed and execution continues. @SYSTEM.RETURN.CODE will be set to lock.number.

 

If the lock is owned by another process and the NO.WAIT option has been used, a message is displayed indicating the unavailability of the lock and the process continues. The value of @SYSTEM.RETURN.CODE will be negative (-ER$LCK) and can be tested to check for this situation in paragraphs.

 

If the lock is owned by another process and the NO.WAIT option has not been used, a message is displayed indicating that the process is waiting and execution is suspended until the lock becomes available. The break key may be used to interrupt this wait.

 

 

Examples

 

LOCK 5

Set task lock 5

 

In this example, task lock 5 was available when the LOCK command was executed.

 

 

LOCK 5

Waiting for task lock to become available

 

In this example, task lock 5 held by another process when the LOCK command was executed. The process waits for the lock to become available.

 

 

LOCK 5 NO.WAIT

Task lock is already in use

 

As in the previous example, task lock 5 was held by another process when the LOCK command was executed. In this case, the NO.WAIT option causes the process to continue without waiting for the lock to become available.

 

 

See also:

CLEAR.LOCKS, LIST.LOCKS, LOCK (command), LOCK (QMBasic), TESTLOCK(), UNLOCK