0
861views
What is meant by deadlock? Describe any three methods to prevent the deadlock.
1 Answer
0
8views

Deadlock: A deadlock, also called as deadly embrace, is a situation in which two threads are each unknowingly waiting for resource held by other. Deadlock is the situation in which multiple concurrent threads of execution in a system are blocked permanently because of resources requirement that can never be satisfied.

In this example, task #1 wants the scanner while holding the printer. Task #1 cannot proceed until both the printer and the scanner are in its possession.

Task #2 wants the printer while holding the scanner. Task #2 cannot continue until it has the printer and the scanner.

Because neither task #1 nor task#2 is willing to give up what it already has, the two tasks are now deadlocked because neither can continue.

Methods of avoid Deadlock-
a) Mutual exclusion-If we could arrange matters such that no two processes were ever in their critical sections simultaneously, we could avoid race conditions. We need four conditions to hold to have a good solution for the critical section problem (mutual exclusion).
1) No two processes may at the same moment inside their critical sections.
2) No assumptions are made about relative speeds of processes or number of CPUs.
3) No process should outside its critical section should block other processes.
4) No process should wait arbitrary long to enter its critical section.

b) Hold & wait or resource holding- Hold and wait or resource holding: a process is currently holding at least one resource and requesting additional resources which are being held by other processes.
c) No preemption: a resource can be released only voluntarily by the process holding it.
d) Circular wait: a process must be waiting for a resource which is being held by another process, which in turn is waiting for the first process to release the resource. In general, there is a set of waiting processes,
P = {P1, P2, …, PN}, such that P1 is waiting for a resource held by P2, P2 is waiting for a resource held by P3 and so on until PN is waiting for a resource held by P1.

Please log in to add an answer.