Operating Systems - Deadlocks (Night Class)
Compiled
By Aurelie A. Peralta
A deadlock
state occurs when two or more processes are waiting indefinitely for an event that
can be caused only by one of the waiting processes. Principally, there are three
methods for dealing with deadlocks:
1. Use
some protocol to prevent or avoid deadlocks, ensuring that the system will never
enter a deadlock state.
2. Allow
the system to enter deadlock state, detect it, and then recover.
3. Ignore
the problem all together, and pretend that deadlocks never occur in the system.
This solution is the one used by most operating systems, including UNIX.
A deadlock
situation may occur if and only four necessary conditions hold simultaneously in
the system: mutual exclusion, hold and wait, no preemption, and circular wait. To
prevent deadlocks, we ensure that at least one of the necessary conditions never
holds.
Another
method for avoiding deadlocks that is less stringent than the prevention algorithms is to have a priori information on how each process will be utilizing the resources.
The banker’s algorithm, for example, needs to know the maximum number of each resource class that may be requested by each process. Using this information, we can define
a deadlock-avoidance algorithm.
If a system
does not employ a protocol to ensure that deadlocks will never occur, then a detection-and-recovery
scheme must be employed. A deadlock-detection algorithm must be invoked to determine
whether a deadlock has occurred. If a deadlock is detected, the system must recover
either by terminating some of the deadlock processes, or by preempting resources
from some of the deadlocked processes.
In a system
that selects victims for rollback primarily on the basis of cost factors, starvation
may occur . As a result, the selected process never completes its designated task.
Reference: Operating System Concepts by Silberschatz, Galvin, and Gagne, 2003