Aneesh Banerjee - 56
Aneesh Banerjee - 56
TOPIC: Deadlock
Deadlock
When two or more processes in a computer system are stuck waiting for each other to release
a resource, it's known as a deadlock.
Requests a resource
Use the resource
Releases the resource
In operating systems, a scenario arises when two or more processes have some resources and
wait for other processes to hold other resources (s). For instance, in the figure below, process
2 is waiting for resource 1, while process 1 is keeping resource 1 and holding it until process
2 acquires it.
This can be pictured as a dead end where nothing can be done. In multi-threaded and
distributed systems, where resource sharing is prevalent, deadlocks are especially
problematic.
1|Pa ge
3. No Pre-emption: Resources must be released willingly by the processes holding
them; they cannot be grabbed by force.
4. Circular Wait: There must be a set of processes such that they create a circular chain
where each process waits for a resource held by the next in the set.
Deadlock Avoidance
Making sure the system never reaches a dangerous condition where a deadlock could happen
is known as deadlock avoidance. This is accomplished by dynamically assessing the
condition of resource allocation and taking appropriate action to prevent possible deadlocks.
Edgar Dijkstra created the well-known deadlock avoidance algorithm known as the Banker's
Algorithm. It functions by mimicking resource allocation and guaranteeing that there is
always a safe resource allocation sequence that permits all processes to finish without
experiencing a deadlock. The following are checked by the algorithm:Maximum Need: The
maximum number of resources each process may request.
By ensuring that the system remains in a safe state, deadlock avoidance prevents the
occurrence of deadlocks.
Deadlock Prevention
In order to avoid deadlocks, deadlock prevention attempts to guarantee that at least one of
the prerequisites for a deadlock cannot hold. There are several ways to accomplish this:
1. Mutual Exclusion: Make resources shareable wherever possible. For example, read-
only files can be shared among multiple processes.
2. Hold and Wait: Require processes to request all the resources they need at once,
before starting execution. This can lead to low resource utilization but prevents
deadlocks.
3. No Pre-emption: Allow pre-emption of resources. If a process holding some
resources requests another resource that cannot be immediately allocated, all resources
currently held by the process are pre-empted and added to the list of available
resources.
4. Circular Wait: Impose a total ordering of all resource types and require that each
process requests resources in an increasing order of enumeration. This prevents the
formation of circular wait chains.
2|Pa ge
Deadlock Detection
Deadlock detection entails the system searching for deadlocks on a regular basis and
resolving them. Usually, techniques that identify cycles in the resource allocation
graph are used for this. A cycle suggests that there is a deadlock if one is found. After
that, the system can take remedial measures like:
Conclusion
In conclusion, deadlocks pose a serious problem for computer systems because they cause
processes to become permanently stopped while they wait for resources that are shared by
other processes. It is crucial to comprehend the ideas of deadlock avoidance, prevention, and
detection while building reliable systems that can manage resource allocation effectively.
Deadlock avoidance ensures that the system never enters an unsafe state by dynamically
analysing resource requests and allocations. Deadlock prevention proactively eliminates
one or more of the necessary conditions for deadlock, thereby preventing its occurrence.
Deadlock detection involves periodically checking for deadlocks and taking corrective
actions to resolve them.
By putting these tactics into practice, system designers may guarantee efficient and effective
operation, lowering the possibility of deadlocks and preserving system stability. The
advantages and disadvantages of each technique vary, and the choice of approach is
contingent upon the particular needs and limitations of the system under design.
3|Pa ge