Question 2 -- 10 points
Part 1 (6 points)
State the four necessary conditions for deadlock, and common ways (citing
specific examples) in which
each can be bypassed for deadlock prevention.
Part 2 (4 points)
Define the concept of ``safe states'' and state how they are
used in deadlock avoidance.
Answer
Part 1
- Mutual exclusion: Resources must be unsharable. To
bypass this, you must have a sharable resource such as
a read-only file or a read-only
data structure in a thread-based system. Most resources are
inherently non-sharable, however.
- Hold and wait: You must be holding one resource and
waiting for another. One way to break this condition is to require
that you apply for locking all resources at once, and you may not
continue until you get them all. In that way you can't have
hold and wait.
- No preemption: You can't force a resource to be taken
away from another process. Like mutual exclusion, in order to
bypass this requirement, you need to have a preemptible resource
such as a CPU, or a block of memory. Other resources (like a
printer) are inherently non-preemptible.
- Circular Wait: You can break circular waiting by
enforcing an numbering on all of the resources, and then
mandating that a process cannot request to lock a resource whose
numbering is less than any resources that it already holds.
Often this cannot be enforced in general programs, but within
an operating system, these orderings can be enforced.
Part 2
To employ the concept of safe states, processes must specify their
maximum resource needs to the operating system. A safe state is
then defined to be one in which you can find an ordering of the
processes such that if the processes executed to completion in
that order, then each could be granted its maximum resource needs.
(Upon completion, each process releases the resources that
it currently holds.)
If the computer system is always in a safe state, then it will
be deadlock free. There are unsafe states that are not deadlock
states, and that may not lead to deadlock states, but these must
be avoided if we are to ensure a deadlock-free system.
Grading
Part 1
1.5 points per part. 1 for the specification, 0.5 for the example of
bypassing.
Part 2
4 points, partitioned as follows:
- The processes must state their maximum needs: 1 point.
- You define the safe state: 2 points.
- You state that the OS must enforce that the system is always in
a safe state: 1 point.
Histogram