Deadlock
Deadlock
Deadlocks
System Model
Deadlock Characterization
Deadlock Prevention
Deadlock Avoidance
Deadlock Detection
Mutual Exclusion: Two or more resources are non-shareable (Only one process
Hold and Wait: A process is holding at least one resource and waiting for
resources.
Circular Wait: A set of processes waiting for each other in circular form.
Mutual Exclusion
There should be a resource
that can only be held by one
process at a time. In the
diagram below, there is a
single instance of Resource 1
and it is held by Process 1
only.
Hold and Wait
A process can hold multiple
execution is complete.
Circular Wait
A process is waiting for the resource held
Request : The process requests the resource. If the request cannot be granted
immediately (for example, if the resource is being used by another process),the
requesting process must wait until it can acquire the Resource.
Use: The process can operate on the resource (for example, if the resource is
a printer, the process can print on the printer)
identifier.
Processes − The system has a set of processes that request and release
If the resource is available, it will be allocated to the process. When a process is finished using
Resource Dependency − Some processes may require multiple resources to complete their
tasks. A resource dependency graph can be used to represent the relationships between
Deadlock Detection − A deadlock can occur when two or more processes are waiting for
resources that are being held by other processes, creating a circular dependency. Deadlock
detection algorithms can be used to detect when a deadlock has occurred, so that corrective
breaking the circular dependency between the processes. This can be done by
releasing one or more resources that are being held by a process, or by preempting
deadlock. The operating system can preempt resources from one or more processes
involved in the deadlock and allocate them to the processes that need them.
the resources that are required to resolve the deadlock are preempted, while in
global preemption, all the resources held by the deadlocked processes are
preempted.
When a process is terminated, all the resources held by the process are
released, and other processes can proceed. However, this approach can
lead to data loss and inconsistency if the terminated process was in the
possibility of deadlock.
Resource-Allocation Graph
A set of vertices V and a set of
edges E.
system.
R = {R1, R2, …, Rm}, the set consisting of all resource types in the
system.
Pi requests instance of Rj
Pi
Rj
Pi is holding an instance of Rj
Pi
Rj
Resource-Allocation Graph
Single and multiple instance without deadlock
Methods for Handling Deadlocks
Generally speaking, we can deal with the deadlock problem in one of
three ways:
We can use a protocol to prevent or avoid deadlocks, ensuring that the
We can allow the system to enter a deadlocked state, detect it, and
recover.
We can ignore the problem altogether and pretend that deadlocks never
Deadlock Prevention
Deadlock Avoidance
Deadlock Prevention
It is very important to prevent a deadlock before it can occur. So,
Deadlock Avoidance
It is better to avoid a deadlock rather than take measures after
the deadlock has occurred. The wait for graph can be used for
deadlock avoidance. This is however only useful for smaller
databases as it can get quite complex in larger databases.
Deadlock Detection and Recovery
The OS doesn't apply any mechanism to avoid or prevent