If you are locking more than one RIN at a time in your program,
there is a chance that you can cause a deadlock between two or
more processes. Deadlock occurs when two or more processes are
mutually blocked, waiting for each other to release a needed
resource.
Example 2-6 illustrates how a deadlock can occur
between two processes, Process A and Process B. Assume that
both processes in the example are executing concurrently, line by
line.
Figure 2-6 Figure 2-6.
{ PROCESS A EXECUTING } { PROCESS B EXECUTING }
. .
. .
. .
LOCKGLORIN (1); LOCKGLORIN (2);
LOCKGLORIN (2); LOCKGLORIN (1);
PROCESS A REMAINS BLOCKED PROCESS B REMAINS BLOCKED
UNTIL RIN 2 IS UNLOCKED UNTIL RIN 1 IS UNLOCKED
BY PROCESS B. PROCESS A BY PROCESS A. PROCESS B
CANNOT UNLOCK RIN 1 WHILE CANNOT UNLOCK RIN 2 WHILE
BEING BLOCKED BEING BLOCKED
|
In Example 2-6, Process A successfully locks global RIN 1, then
attempts to lock global RIN 2 (already locked by Process B).
Process A is blocked until it can successfully lock global RIN 2.
While Process A is blocked, it cannot unlock global RIN 1, thus
making global RIN 1 unavailable for locking by Process B.
Process B, meanwhile, has locked global RIN 2 and has been
blocked attempting to lock global RIN 1 (locked, or course, by
Process A). Global RIN 2 remains unavailable to Process A.
Both Process A and Process B find themselves mutually blocked and
in the state of deadlock. Even if subsequent code in both
program files unlocks one or both global RINs, neither process can
execute that code.
One way to avoid deadlocks is by ranking the RINs used by
cooperating processes. In Example 2-5, cooperating processes agree
to first attempt to lock RIN 1 before attempting to lock RIN2. In
addition, the processes that have successfully locked both RINs
agree to unlock the two RINs in the reverse order, first RIN
2, then RIN 1. Because cooperating processes must lock
RINs in ascending order and unlock them in descending order, deadlock
cannot occur.
If you have only standard user capabilities and deadlock occurs
between two or more processes in your program's process
structure, you must abort your program to resolve the deadlock.
If you have Multiple RIN (MR) Capability and deadlock
occurs between your program and processes located in different
jobs/sessions, you must immediately contact your System Manager
to resolve the deadlock.