Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Deadlock Notes

Deadlockfooter line

 

In a multiprogramming system, several processes may compete for a finite number of resources. A process requests for resources, and if the resources are not available at the time then the process enters the waiting state. Sometimes, a process will wait indefinitely because the resources it has requested for are being held by other similar waiting processes.

Deadlock is a state in which two or more processes are waiting indefinitely because the resources they have requested for are being held by one another.

 

A process is deadlocked if it is waiting for an event which is never going to happen.  Deadlocks can occur via system calls, locking, etc.

 

 

Example of deadlock

 

 

Let S and Q be two semaphores initialized to 1 
      P0                         P1 
wait (S);                    wait (Q);
wait (Q):                   wait (S);
.
.
.
signal (S);                 signal (Q); 
signal (Q);                signal (S);