The UNLOCK function gives up ownership of an interlock. If the UNLOCK succeeds, the following effects occur:
-
If no process is waiting to acquire the interlock, then the state of the interlock changes to FREE and the system changes the stack number stored in the interlock to 0.
-
If one process is waiting to acquire the interlock, then the state of the interlock changes to LOCKED_UNCONTENDED, and the system changes the stack number in the interlock to record the new owner.
-
If multiple processes are waiting to acquire the interlock, then the state of the interlock is LOCKED_CONTENDED. The highest-priority process acquires the interlock. Note, however, that process priority is affected by a number of factors aside from the PRIORITY task attribute. Therefore, the programmer cannot use the PRIORITY task attribute to determine which of the contending processes will acquire the interlock.
Additionally, the system changes the stack number in the interlock to record the new owner. The state of the interlock remains LOCKED_CONTENDED.
The UNLOCK function is typically used by the current owner of the interlock. However, it is also possible for a process to UNLOCK an interlock owned by another process.
The UNLOCK function is of type INTEGER and returns one of the following values:
|
Value |
Meaning |
|---|---|
|
1 |
The interlock was successfully unlocked. |
|
2 |
The interlock has a state of FREE and therefore cannot be unlocked. |
UNLOCK can be used as a statement rather than a function. However, if the UNLOCK statement does not finish successfully, the system discontinues the process executing the UNLOCK statement.
Following are examples of UNLOCK functions:
I := UNLOCK (MYLOCK) I := UNLOCK (YOURLOCKS [2])

