DEADLOCK
Suruthi Rajendran
Web developer | UI/UX Designer | Design thinker . Seeking insights through full-stack development and visualizations .
Deadlock in OS refers to a situation where more than one or two processes or threads are not able to proceed because each is waiting for the other to release a resource. In other words, it’s a state where a group of processes become stuck in a way that they can’t make any progress. Deadlock usually occurs in systems where multiple processes compete for limited resources such as CPU time, memory or input or output devices.?
Necessary conditions for Deadlock?
There are four necessary conditions for a Deadlock to occur, often referred to as Deadlock conditions. Here are the following essential conditions for Deadlock:?
1) Mutual exclusion: In this condition, only one method must be non-shareable. It means only one process can use it at a time. This condition ensures that a resource cannot be simultaneously accessed or modified by multiple processes.??
2) Hold and wait: The process must hold at least one resource while waiting to acquire additional resources. This condition can lead to a situation where processes hold some resources and wait indefinitely for others.??
3) No pre-emption: Resources cannot be pre-empted or forcibly taken away from a process. This means that a resource can only be released voluntarily by the process holding it. If a process is holding a resource and cannot complete its task due to waiting for another resource, it will not release its current resource, contributing to a potential Deadlock.?
4) Circular wait: There must be a circular chain of one or more processes, each of which is waiting for a resource held by another process in the chain. This circular waiting pattern means that no process in the cycle can make progress because another process blocks it.?
Example of Deadlock in OS?
Here's a simple example of a Deadlock involving two processes, Process A and Process B, competing for two resources, Resource X and Resource Y: ?
Initial stage ?
Initial State?
1) Process A holds Resource X and requests Resource Y?
2) Process B holds Resource Y and requests Resource X?
Execution Sequence??
1) Process A starts and acquires Resource X?
2) Process B starts and acquires Resource Y?
Stalemate?
1) Process A requires Resource Y to complete its task, but it can’t proceed because Process B is holding it.??
2) Process B requires Resource X to complete its task but can’t proceed because Process A is holding it.??
Neither Process A nor Process B can release their held resource because they are still waiting for another resource to be released. This circular waiting condition fulfils one of the necessary conditions for Deadlock, leading to a Deadlock situation.?
Methods of Handling Deadlock?
The following are the methods of handling Deadlocks. ?
1) Deadlock prevention: Deadlock prevention strategies aim to eliminate one or more of the necessary conditions for Deadlock. This approach ensures that Deadlock cannot occur in the system.? One common method involves resource allocation graphs or resource allocation policies to track and manage resource allocation.??
2) Deadlock detection and recovery: Deadlock detection is a process of periodically checking the system for the existing Deadlocks.? Once the Deadlock is detected, the system can take action to resolve it. Detection and recovery are reactive approaches to managing Deadlocks after they occur.?
3) Deadlock avoidance: Deadlock avoidance uses resource allocation algorithms and request protocols to dynamically allocate resources in a way that prevents the system from entering a Deadlock state. The key is to make sure that resource requests do not lead to situations where all necessary conditions for Deadlock are met.?
4) Wound-wait schemes: Wound-wait scheme handles Deadlock situations in the Data Management system, allowing either older transactions to wait or younger transactions to wait and deciding which one should be aborted based on their age.?
5) Limit resource utilisation: This method involves limiting the huge number of resources that can be allocated to a process. By restricting resource usage, the system reduces the likelihood of Deadlock occurrence. However, this approach may impact system efficiency and resource utilisation, so it should be used judiciously.?
Benefits of Deadlock Method?
The following are the benefits of the Deadlock method:??
1) Proactive approach: The Deadlock Method ensure that Deadlock cannot occur by eliminating one or more necessary conditions.??
2) Resource reclamation: The recovery method can potentially free up resources, allowing another process to continue execution. This can minimise the impact of Deadlock on system performance.?
3) Risk reduction: By restricting the maximum number of resources that can be allocated to the process, this method reduces the risk of Deadlock. It provides a very easy way to make sure that processes do not consume an excessive number of resources.
4) Resource guarantees: It can provide resource guarantees to critical processes and ensure that certain resources remain available for essential tasks.? ?
5) Detection and resolution: Deadlock detection and recovery methods allow systems to detect and resolve Deadlocks when they do occur. This capability ensures that the system can continue functioning even in Deadlocks, improving system robustness. ?
#snsdesignthinkers
#snsinstitutions
#designthinking