Deadlocks Flashcards
Give an example of a deadlock taken from politics.
In the U.S., consider a presidential election in which three or more candidates are trying for the
nomination of some party. After all the primary elections are finished, when the delegates
arrive at the party convention, it could happen that no candidate has a majority and that no
delegate is willing to change his or her vote. This is a deadlock. Each candidate has some
resources (votes) but needs more to get the job done. In countries with multiple political parties
in the parliament, it could happen that each party supports a different version of the annual
budget and that it is impossible to assemble a majority to pass the budget. This is also a
deadlock.
Students working at individual PCs in a computer laboratory send their files to be printed
by a server that spools the files on its hard disk. Under what conditions may a deadlock occur
if the disk space for the print spool is limited? How may the deadlock be avoided?
Disk space on the spooling partition is a finite resource. Every block that comes in de facto
claims a resource and every new one arriving wants more resources. If the spooling space is,
say, 10 MB and the first half of ten 2-MB jobs arrive, the disk will be full and no more blocks can
be stored so we have a deadlock. The deadlock can be avoided by allowing a job to start printing
before it is fully spooled and reserving the space thus released for the rest of that job. In this
way, one job will actually print to completion, then the next one can do the same thing. If jobs
cannot start printing until they are fully spooled, deadlock is possible.
In the preceding question (Students working at individual PCs in a computer laboratory send their files to be printed by a server that spools the files on its hard disk.), which resources are preemptable and which are
nonpreemptable?
The printer is nonpreemptable; the system cannot start printing another job until the previous
one is complete. The spool disk is preemptable; you can delete an incomplete file that is
growing too large and have the user send it later, assuming the protocol allows that.
In Fig. 6-1 (https://imgur.com/a/jtqLB7X) the resources are returned in the reverse order of their acquisition. Would giving
them back in the other order be just as good?
Yes. It does not make any difference whatsoever.
The four conditions (mutual exclusion, hold and wait, no preemption and circular wait) are
necessary for a resource deadlock to occur. Give an example to show that these conditions
are not sufficient for a resource deadlock to occur. When are these conditions sufficient for a
resource deadlock to occur?
Suppose that there are three processes, A, B and C, and two resource types, R and S. Further
assume that there are one instance of R and two instance of S. Consider the following execution
scenario: A requests R and gets it; B requests S and gets; C requests S and gets it (there are two
instances of S); B requests R and is blocked; A requests S and is blocked. At this stage all four
conditions hold. However, there is no deadlock. When C finishes, one instance of S is released
that is allocated to A. Now A can complete its execution and release R that can be allocated to
B, which can then complete its execution. These four conditions are enough if there is one
resource of each type.
City streets are vulnerable to a circular blocking condition called gridlock, in which
intersections are blocked by cars that then block cars behind them that then block the cars
that are trying to enter the previous intersection, etc. All intersections around a city block are
filled with vehicles that block the oncoming traffic in a circular manner. Gridlock is a resource
deadlock and a problem in competition synchronization. New York City’s prevention
algorithm, called ‘don’t block the box,’ prohibits cars from entering an intersection unless the
space following the intersection is also available. Which prevention algorithm is this? Can you
provide any other prevention algorithms for gridlock?
“Don’t block the box” is a pre-allocation strategy, negating the hold and wait deadlock
precondition, since we assume that cars can enter the street space following the intersection,
thus freeing the intersection. Another strategy might allow cars to temporarily pull into garages
and release enough space to clear the gridlock. Some cities have a traffic control policy to shape
traffic; as city streets become more congested, traffic supervisors adjust the settings for red
lights in order to throttle traffic entering heavily congested areas. Lighter traffic ensures less
competition over resources and thus lowers the probability of gridlock occurring.
Suppose four cars each approach an intersection from four different directions
simultaneously. Each corner of the intersection has a stop sign. Assume that traffic regulations
require that when two cars approach adjacent stop signs at the same time, the car on the left
must yield to the car on the right. Thus, as four cars each drive up to their individual stop
signs, each waits (indefinitely) for the car on the left to proceed. Is this anomaly a
communication deadlock? Is it a resource deadlock?
(FFE18)
The above anomaly is not a communication deadlock since these cars are independent of each
other and would drive through the intersection with a minimal delay if no competition occurred.
It is not a resource deadlock, since no car is holding a resource that is requested by another car.
Nor would the mechanisms of resource pre-allocation or of resource preemption assist in
controlling this anomaly. This anomaly is one of competition synchronization, however, in which
cars are waiting for resources in a circular chain and traffic throttling may be an effective
strategy for control. To distinguish from resource deadlock, this anomaly might be termed a
“scheduling deadlock”. A similar deadlock could occur following a law that required two trains
merging onto a shared railroad track to wait for the other to proceed. Note that a policeman
signaling one of the competing cars or trains to proceed (and not the others) can break this
dead state without rollback or any other overhead.
Is it possible that a resource deadlock involves multiple units of one type and a single unit
of another? If so, give an example.
(TUT13)
It is possible that one process holds some or all of the units of one resource type and requests
another resource type, while another process holds the second resource while requesting the
available units of the first resource type. If no other process can release units of the first
resource type and the resource cannot be preempted or used concurrently, the system is
deadlocked. For example, two processes are both allocated memory cells in a real memory
system. (We assume that swapping of pages or processes is not supported, while dynamic
requests for memory are supported.) The first process locks another resource - perhaps a data
cell. The second process requests the locked data and is blocked. The first process needs more
memory in order to execute the code to release the data. Assuming that no other processes in
the system can complete and release memory cells, a deadlock exists in the system.
Fig. 6-3 (https://imgur.com/a/zNOS9Js) shows the concept of a resource graph. Do illegal graphs exist, that is, graphs that
structurally violate the model we have used of resource usage? If so, give an example of one.
Yes, illegal graphs exist. We stated that a resource may only be held by a single process. An arc
from a resource square to a process circle indicates that the process owns the resource. Thus, a
square with arcs going from it to two or more processes means that all those processes hold the
resource, which violates the rules. Consequently, any graph in which multiple arcs leave a
square and end in different circles violates the rules unless there are multiple copies of the
resources. Arcs from squares to squares or from circles to circles also violate the rules.
Consider Fig. 6-4 (https://imgur.com/a/NX5BFXM). Suppose that in step (o) C requested S instead of requesting R. Would
this lead to deadlock? Suppose that it requested both S and R.
Neither change leads to deadlock. There is no circular wait in either case.
Suppose that there is a resource deadlock in a system. Give an example to show that the
set of processes deadlocked can include processes that are not in the circular chain in the
corresponding resource allocation graph.
Consider three processes, A, B and C and two resources R and S. Suppose A is waiting for I that is
held by B, B is waiting for S held by A, and C is waiting for R held by A. All three processes, A, B
and C are deadlocked. However, only A and B belong to the circular chain.
In order to control traffic, a network router, A periodically sends a message to its
neighbor, B, telling it to increase or decrease the number of packets that it can handle. At
some point in time, Router A is flooded with traffic and sends B a message telling it to cease
sending traffic. It does this by specifying that the number of bytes B may send (A’s window
size) is 0. As traffic surges decrease, A sends a new message, telling B to restart transmission.
It does this by increasing the window size from 0 to a positive number. That message is lost.
As described, neither side will ever transmit. What type of deadlock is this?
This is a communication deadlock, and can be controlled by having A time out and retransmit its
enabling message (the one that increases the window size) after some period of time (a
heuristic). It is possible, however, that B has received both the original and the duplicate
message. No harm will occur if the update on the window size is given as an absolute value and
not as a differential. Sequence numbers on such messages are also effective to detect
duplicates.
The discussion of the ostrich algorithm mentions the possibility of process-table slots or
other system tables filling up. Can you suggest a way to enable a system administrator to
recover from such a situation?
A portion of all such resources could be reserved for use only by processes owned by the
administrator, so he or she could always run a shell and programs needed to evaluate a
deadlock and make decisions about which processes to kill to make the system usable again.
Consider the following state of a system with four processes, P1, P2, P3, and P4, and five
types of resources, RS1, RS2, RS3, RS4, and RS5:
(https://imgur.com/a/SYuSlhq)
Using the deadlock detection algorithm described in Section 6.4.2, show that there is a
deadlock in the system. Identify the processes that are deadlocked.
(TUT13)
First, the set of unmarked processes, P = (P1 P2 P3 P4)
● R1 is not less than or equal to A
● R2 is less than A; Mark P2; A = (0 2 0 3 1); P = (P1 P3 P4)
● R1 is not less than or equal to A
● R3 is equal to A; Mark P3; A = (0 2 0 3 2); P = (P1 P4)
● R1 is not less than or equal to A
● R4 is not less than or equal to A
Processes P1 and P4 remain unmarked that means they are deadlocked
Consider the following state of a system with four processes, P1, P2, P3, and P4, and five
types of resources, RS1, RS2, RS3, RS4, and RS5:
(https://imgur.com/a/SYuSlhq)
Explain how the system can recover from the deadlock in this problem using
a) recovery through preemption.
b) recovery through rollback.
c) recovery through killing processes.
(TUT13)
Answer:
a) Recovery through preemption: After processes P2 and P3 complete, process P1 can be
forced to preempt 1 unit of RS3. This will make A = (0 2 1 3 2), and allow process P4 to
complete. Once P4 completes and release its resources P1 may complete.
b) Recovery through rollback: Rollback P1 to the state checkpointed before it acquired RS3.
Recovery through killing processes:
c) Kill P1.