The LOCK function attempts to secure ownership of an interlock. If the LOCK succeeds, the following effects occur:
-
The state of the interlock changes to LOCKED_CONTENDED or LOCKED_UNCONTENDED (depending on whether other processes are also waiting to secure this lock).
-
The system updates the interlock to record the stack number of the process that now owns the interlock.
The LOCK function can specify any of several actions to take if the requested interlock is not immediately available. The following are examples:
RSLT := LOCK (LK1);
Wait indefinitely.
RSLT := LOCK (LK1, 60);
Wait with 60-second time limit.
RSLT := LOCK (LK1, 0);
Abandon lock attempt if interlock is unavailable.
RSLT := LOCK(LK1, EVENT2);
Wait with option of being interrupted by event EVENT2.
RSLT := LOCK [INTERRUPTIBLE] (LK1);
Wait with option of being interrupted by receipt of a signal. Signals are a feature of the POSIX environment. For an overview of signals, refer to the POSIX User's Guide.
RSLT := LOCK [DSABLE] (LK1);
Wait with the following conditions:
-
If the process has already been discontinued, the wait is abandoned. This situation can occur if the LOCK function is executed in an EPILOG or EXCEPTION procedure.
-
Once the process is waiting, if a DS (Discontinue) system command is received, the wait is abandoned.
The DSABLE option is implemented in DMALGOL and NEWP because programs in these languages are capable of entering a state in which they would otherwise be immune to DS commands. The DSABLE option is not available in ALGOL because ALGOL interlocks can be discontinued anyway.
If the DSABLE option is used, then the INTERRUPTIBLE option cannot be used. However, the INTERRUPTIBLE option includes the effects of the DSABLE option.
The LOCK function is of type INTEGER and returns one of the following values:
|
Value |
Meaning |
|---|---|
|
0 |
A signal was received or a DS command was received before the interlock could be acquired. |
|
1 |
The interlock was successfully acquired. |
|
2 |
The timeout elapsed or the event HAPPENED before the interlock could be acquired. |
LOCK can be used as a statement rather than a function. However, if the LOCK statement does not finish successfully, the system discontinues the process executing the LOCK statement.

