Operating System Deadlock Prevention in OS | Algorithms (Techniques)

Deadlock Prevention in OS | Algorithms (Techniques)

It is very necessary to prevent deadlock in operating system before it can happen. So, system identifies every transaction before getting its execution, and ensures it doesn’t get to deadlock problem.

Deadlock Prevention in OS | Algorithms (Techniques)

If, that time any transaction may occur deadlock issue, then it can’t get to execute its instructions.

We have two techniques to prevent the deadlock problem, such as:-

  • Deadlock Prevention Schemes- Wait Die Scheme and Wound Wait Scheme
  • To Violate any One Condition from Four Conditions (Mutual Exclusion, Hold and Wait, No Preemption, Circular Wait)

In deadlock prevention schemes, we implement the timestamp, and to get ensure that deadlock doesn’t happen that given as follows.

  • Wait Die Scheme

This scheme, transaction T1 fires to request for getting resource but that same resource held by the other transaction T2. Then two condition can be occurring such as:

A). TS (T1) < TS (T2), means that if T1 is older than to T2, so T1 visited in your system before to T2. T1 is getting to wait for resource that will be free when T2 has done its entire execution.

B). TS(T1) > TS(T2), means that T1 is smaller to T2, so T1 get visiting in your system after T2, then T2 is dropped. So it again started along with same timestamp.

  • Wound Wait Scheme

If transaction T1 fires to request for getting resource but that same resource held by the other transaction T2, then two condition can ocurr such as:

A). TS(T1) < TS(T2), means that if T1 is older than to T2, so T1 visited in your system before to T2, then T1 is getting to roll back T2 or wound T2. So T1 obtains some resource and done its entire execution. Then T2 further again started along with same timestamp.

B). TS(T1) > TS(T2), means that T1 is smaller to T2, so T1 visited in your system after T2, then T2 dropped. So it again started along with same timestamp.

To Violate any One Condition from Four Condition

In the Mutual Exclusion, one resource get assign by single process at same time. If other process needs to same allotted resources; then it has to required wait to occupy for those resources.

Also Read: What is Deadlock in OS? Handling Methods & Examples

So, Mutual Exclusion can’t breake for process because in practically, single resource can conduct the task of one process at once. For instance – Multiple users can’t fire commands to print document at same time.

Avoid Mutual Exclusion – To avoid mutual exclusion, it can be using the “Spooling” technique. In the Spooling, all jobs of each process allow to link with memory. For example, Printer uses of those jobs and produce the output of all jobs according to FCFS (First Come First Serve) principle, because in which any process does not need to wait to print.

This condition occur, if one process holds few resources. And, it has to wait for further resources which already held by another waiting process.

For avoiding that problem, before turn-on execution, process would be alloting whole resources which needed. Then finally it will start its execution. In this approach, process has not needed to wait for few resources while its execution. This technique is not valid because, we don’t aware about that resource needed by process in further life in execution.

To avoid hold and wait, we can use another method that is “Do Not Hold”. For instance, if process required 20 resources N1, N2, N3, .. N20. At the specific time slot, we can release N1, N2, N3, N4, N5, and N6.  After completing that job on those resources, process has to need to free those resources, and other resources will be delivering to process. So with using this concept, we can avoid the hold and wait problem. 

It is a technique in which one process cannot take the resources of other processes by force. But if we find some resources that are causing a system deadlock, then we can stop that resource from holding that resource.

By doing so, we can overcome the deadlock but there are some things that must be keeping in mind before using this forceful approach. If the process is of a very high priority or the process is a system process, then only the process can bind the resources of other processes to the former. In addition, try to prefigure the resources of processes that are in a state of waiting.

If, first process is waiting for such resource that held by second process. And, this process is again waiting for such resource which held by third process and so on. Then we can say that Circular wait’s condition get occur.

To avoid circular wait condition, some priority numbers are allotted to every resource. And process has not permission to fire request for lesser priority resource. This ensures that not a single process can request a resource which is being utilized by some other process and no cycle will be formed.

Leave a Reply

Your email address will not be published. Required fields are marked *