Friday, October 21, 2016

                               Deadlock   

      Earlier the computer operating system ran only one program at a time. All the resources of the system were available to this one program. As technology developed, operating system ran multiple programs at once, interleaving them.This brought in the problem of Deadlock. Deadlock is a situation in which two computer programs share the same resources and effectively prevent each other from accessing the resources which results in both programs ceasing to function. In other words, this is a condition that occurs when two processes are each waiting for the each other to complete before proceeding and thus, the result is that both processes hang. Deadlocks mostly occur in multitasking and client/server environments.

What are the necessary conditions ?

There are four necessary conditions to achieve deadlocks :-

1) Mutual Exclusion: At least one resource must be held in a non-shareable mode; If any other process requests this resource, then the process must wait for the resource to be released.

2) Hold and Wait :A process must be simultaneously holding at least one resource and waiting for at least one resource that is currently being held by some other process.

3) No preemption: Once a process is holding a resource, then that resource cannot be taken away from that process until the process voluntarily releases it.
4)Circular Wait : A set of processes {P0,P1,P2, ....PN } must exist such that every P[i] is waiting       for P[(i+1)%(N+1)].



How to handle a deadlock ?


1)Generally speaking there are three ways of handling deadlocks:
  • Deadlock prevention or avoidance - Do not allow the system to get into a deadlocked state.
  • Deadlock detection and recovery - Abort a process or preempt some resources when deadlocks are detected.
  • Ignore the problem all together - If deadlocks only occur once a year or so, it may be better to simply let them happen and reboot as necessary than to incur the constant overhead and system performance penalties associated with deadlock prevention or detection. 

2) In order to avoid deadlocks, the system must have additional information about all processes. In particular, the system must know what resources a process will or may request in the future.

3)Deadlock detection is fairly straightforward, but deadlock recovery requires either aborting processes or preempting resources, neither of which is an attractive alternative.

4)If deadlocks are neither prevented nor detected, then when a deadlock occurs the system will gradually slow down, as more and more processes become stuck waiting for resources currently held by the deadlock and by other waiting processes. Unfortunately this slowdown can be indistinguishable from a general system slowdown when a real-time process has heavy computing needs.
_________________________________________________________________________________

Reference

_________________________________________________________________________________

No comments:

Post a Comment