Vous êtes sur la page 1sur 7

CHAPTER - DEADLOCK

DEADLOCK can occur in concurrent environments as a result of uncontrolled granting of system resources to requesting processes. In a multiprogramming environment , several processes may compete for a limited number of resources. A process requests for the required resource and if it is not available then the process has to wait for it. There may be a situation when the process has to wait endlessly because the requested resource may be held by other waiting processes. This type of situation is known as DEADLOCK.

Consider a case where two different processes want to be allocated on the same resource (say printer) at a particular time. If both the processes requests for the same resource then the system will come under the state of deadlock because a single resource can attend only one process at a time. In other words, a printer can print only one process (document) at a time.

Request

RESOURCE A

Held by

PROCESS P1

PROCESS P2

Held by

RESOURCE B

Request

FIGURE - DEADLOCK

A DEADLOCK situation arises if the following four conditions hold simultaneously on the system: 1. Mutual Exclusion : Only one process can use a resource at a time. If another process requests for the resource, the requesting process has to wait until the requested resource is released. 2. Hold and Wait : In this situation, a process might be holding some resource while waiting for additional resource, which is currently being held by other processes. 3. No Preemption : Resources cannot be preemptive, that is, resources cannot be forcibly removed from a process. A resource can only be released voluntarily by the holding process, after that process has completed its task. 4. Circular wait : This situation may arise when a set of waiting processes say P1 and P2 exist in such a way that P1 is waiting for resource that is held by P2, and likewise P2 is waiting for the resource held by P1.

To ensure that deadlock never occur, the system can use either 1. Deadlock Prevention : Deadlock can occur only when all the 4 deadlock causing conditions hold true. Hence, the system should ensure that at least one of the four deadlock causing factors would not hold true so that deadlock can be prevented. 2. Deadlock Avoidance : Additional information concerning which resources a process will require and use during its lifetime, should be provided to the operating system beforehand. For example, in a system with one CD drive and a printer, process P might request first for the CD drive and later for the printer, before releasing

both resources. On the other hand, process Q might request first for the printer and the CD drive later. With this knowledge in advance, the operating system can schedule the resource allocation in such a way that no process to wait for a resource.

Vous aimerez peut-être aussi