Deadlock Prevention in OS (Operating System) | Algorithms (Techniques)

Deadlock Prevention in OS (Operating System) | Algorithms (Techniques)

What Deadlock Prevention

It is very necessary to prevent deadlock in operating system before it can happen. So, system identifys every transaction before getting its execution, and ensures it doesn’t get to deadlock problem. If, that time any transaction may occur deadlock issue, then it can’t get to execute its instructions.

Deadlock Prevention Algorithms

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)

Deadlock Prevention Schemes

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

  • Wait Die Scheme

In this scheme, if transaction T1 fires to request for getting resource but that same resource is held by the other transaction T2, then two condition can be occurred 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 visited in your system after T2, then T2 is dropped. So it is again started along with same timestamp.

  • Wound Wait Scheme

In this scheme, if transaction T1 fires to request for getting resource but that same resource is held by the other transaction T2, then two condition can be occurred 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 is 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 is dropped. So it is again started along with same timestamp.

To Violate any One Condition from Four Condition

  • Mutual Exclusion

In the Mutual Exclusion, one resource is assigned by single process at same time; if other process is needed to same allotted resources then it has to required wait to occupy for those resources. So, Mutual Exclusion can’t be broken 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 used the “Spooling” technique. In the Spooling, all jobs of each process are linked 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.

  • Hold and Wait

This condition is occurred, if one process holds few resources and it has to wait for further resources which are already held by another waiting process.

For avoiding that problem, before turn-on execution, process would be allotted whole resources which are 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 is 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 delivered to process. So with using this concept, we can avoid the hold and wait problem. 

  • No Preemption

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 kept 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.

  • Circular Wait

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

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 *