Deadlock requires four circumstances to occur. For unshareable single instance resources, a deadlock occurs only when all four conditions occur at the same time. We can prevent deadlock if we prevent these four conditions.
In this article, we will look more into the Deadlock Prevention in Operating Systems according to the GATE Syllabus for (Computer Science Engineering) CSE. Let us read ahead to find out more about it.
Table of Contents
- How to Prevent Deadlock in an Operating System?
- Mutual Exclusion
- Hold and Wait
- No Preemption
- Circular Wait
How to Prevent Deadlock in an Operating System?
If we model deadlock with a table standing on four legs, we can also imitate four legs with the four criteria that produce deadlock when they occur concurrently.
However, if one of the table’s legs is broken, the table will undoubtedly fall. In the case of deadlock, we can avoid it if we can breach one of the four required conditions and do not allow them to occur simultaneously. Let’s look at how we may prevent each of these problems.
Mutual Exclusion
In terms of resources, mutual exclusion means that multiple processes can’t use the same resource at the same time. However, while this is reasonable, it results in a deadlock. There will be no process waiting for the resource if we may use the same resource for several processes at the same time. However, if we can prevent the resources from acting in a mutually exclusive manner, we can keep the system from becoming stuck.
Spooling
Simultaneous Peripheral Operations Online is what Spooling stands for. Spooling is used for devices like the printer, mouse, and keyboard. Let’s look at how a printer’s spooling procedure works:
- Memory is connected to a printer.
- We can keep all the jobs stored in all processes with the assistance of this memory.
- The printer then collects all of the jobs and prints each one in an FCFS (First Come, First Serve) manner. No process will have to wait for the printer if we follow this technique.
- Finally, the printer collects the outputs when they have been created.
So, using spooling, we can prevent mutual exclusion; however, we may face two types of issues:
- Spooling cannot be used for all resources.
- When spooling, a rare condition present between the processes may arise in which the processes desire some spool space. We cannot, however, impose the usage of the same resources for several processes. Because this strategy fails now, and if we continue to do so, there is a chance that severe difficulties with the process may occur. As a result, we might conclude that a violation of mutual exclusion is nearly impossible.
Hold and Wait
A hold and wait condition occurs when a process holds a resource while waiting for other resources to complete its task. There is a risk of deadlock in this case because many processes possess one resource and cyclically wait for various other resources to complete their tasks. As a result, we’ll need to come up with a procedure that doesn’t hold any resources or waits for any resources. This means that before beginning the process, we should assign all of the resources that it will require. The process is then started without having to wait for any resources.
In practice, we can only do so if we first identify all of the resources that the procedure will require. Although this sounds highly practical, we cannot do so in a computer system because no process can identify the required resources at the outset.
!(Hold and wait) = !hold or !wait (the negation of hold and wait is that either one doesn’t hold or they don’t wait)
A process is a series of instructions that the CPU executes. Each instruction makes many requests for distinct resources. The operating system, however, cannot control the demand for resources. The following concerns arise from the approach:
- Practically, it is not possible.
- Because the process can retain a resource for a lengthy time in some instances, there is a risk of starving.
No Preemption
The reason for the deadlock is that once the process starts, it cannot be stopped. However, we can avoid deadlock by removing resources from the process that could cause it. However, this is not an appropriate technique because bringing out a resource that is used by the process will be inconsistent with the previous effort.
Example – Let’s say we have a printer that is now being used by a process, and we want to assign the printer to another process. As a result, the data produced by the printer becomes both inaccurate and ineffective. Furthermore, the operation would not resume printing from where it stopped off, resulting in inefficient performance.
Circular Wait
A circular wait occurs when one or more processes wait in a circular order for the resources they require. The problem of a cyclic wait can be solved by assigning a priority number to each resource. A resource with a lower priority value cannot be requested by the process. It ensures that no process can demand a resource that is already in use by another. As a result, no cycle will form.
So, after looking at all of these constraints, we discovered that there is only one feasible strategy to avoiding deadlock, and that approach is indeed a violation of circular wait.
Keep learning and stay tuned to get the latest updates on GATE Exam along with GATE Eligibility Criteria, GATE 2023, GATE Admit Card, GATE Syllabus, GATE Previous Year Question Paper, and more.
Also Explore,
- Batch Operating System
- Binary Semaphores in Operating System
- Contiguous Memory Allocation in Operating System
- Counting Semaphores in Operating System
- Deadlock Detection and Recovery in Operating System
- Distributed Operating System
- Dynamic Partitioning in Operating System
- Fixed Partitioning in Operating System
- Functions of Operating System
- Operating System GATE Questions
- Methods for Handling Deadlock in Operating System
- Multiprocessing Operating System
- Multiprogramming Operating System
- Multitasking Operating System
- Network Operating System
- Non-Contiguous Memory Allocation in Operating System
- Operating System Services
- Paging in OS
- Process in Operating System
- Process Scheduler in Operating System
- Process Scheduling in Operating System
- Process State in Operating System
- Real-Time Operating System
- Resource Allocation Graph in Operating System
- Semaphores in Operating System
- Time-Sharing Operating System
- Types of Operating System
Comments