Conditions for Deadlock in Operating System

By Mona Kumari|Updated : April 25th, 2022

A deadlock occurs in the system when a process cannot proceed because it needs to obtain a resource that is held by another process, but it itself is holding a resource that the other process needs. The examples of deadlock are mentioned below.

  • The system has 2 tape drives. P1 and P2 each hold one tape drive, and each needs another one.
  • Semaphores A and B, initialized to 1. P0 and P1 are in deadlock as follows:
    (a) P0 executes wait (A) and preempts.
    (b) P1 executes wait (B).
    (c) Now, P0 and P1 enter in deadlock.

P0

P1

wait(A);

wait(B);

wait(B);

wait(A);

  • Assume the space is available for allocation of 200Kbytes, and the following sequence of events occur.

P0

P1

……..

Request 80KB;

………

Request 60KB;

 …….

Request 70KB;

…..

Request 80KB;

 Deadlock occurs if both processes progress to their second request.

Table of Content

Condition for Deadlock

In the system, the deadlock occurs when the system has these four conditions simultaneously that are as follows:

  • Mutual Exclusion
  • No-preemption
  • Hold & wait
  • Circular wait

For a deadlock to occur, all four conditions must be met. The impasse is broken if any one of them is averted or resolved.

Mutual Exclusion

When two people meet on the landings, they cannot just stroll through since there is only enough room for one person. The first prerequisite for the occurrence of the deadlock is to enable only one person (or process) to utilize the step between them (or the resource).

  • The resource has to be allocated to only one process, which is freely available.
  • There should be a one-to-one relationship between the resource and process.

No-preemption

To overcome the deadlock, just cancel one of the processes and let the others continue. However, the Operating System does not. It provides resources to the processors for as long as the job requires till it is accomplished. As a result, there is no need for a temporary reallocation of resources. It's the third deadlock condition.

  • The resource has to be voluntarily released by the process after completing the execution.
  • It is not allowed to preempt the resource from the process forcefully.

Hold & wait

Holding occurs when two individuals refuse to retreat and defend their territory. This is the next condition that must be met in order to break the deadlock.

  • A process acquires resources piecemeal. While it awaits allocation and assignment of other resources, it holds on to its acquired resources.
  • In other words, a process waits for some resources while holding another resource simultaneously.

Circular wait

Circular wait occurs when two persons refuse to retreat and wait for each other to recede so that they can finish their work. It's the final thing that can cause a deadlock. Processes waiting for resources from the others form a circular chain. In that chain, each process holds at least one unit resource, which is demanded by the next process in the chain.

Suppose there exists a set {P0, P1,..., P0} of waiting processes such that the process P0 is waiting for a resource that P1 holds, and the process P1 is waiting for a resource that P2 holds. The resource allocation graph is:

 byjusexamprep

Symbol and representation

The circle will represent the process as 

byjusexamprep

Resources will be represented with rectangle blocks as

byjusexamprep

If the process P1 is requested a resource, then it is represented as

byjusexamprep

If the process P1 is holding an instance, then it is represented as

byjusexamprep

BYJU's Exam Prep Online Classroom Program 

Thanks

#DreamStriveSucceed

Comments

write a comment

FAQs

  • A deadlock is a condition where each of the computer processes waits for a resource that is being assigned to some other process. In this situation, none of the processes gets executed since the resource it needs is held by some other process which is also waiting for some other resource to be released.

  • The four conditions that say the deadlock occurs in the system are:

    • Mutual Exclusion
    • No-preemption
    • Hold & wait
    • Circular wait
  • Yes, all these 4 conditions must hold simultaneously for the deadlock occur. If any of these conditions fail, the system can be ensured deadlock-free.

  • No. This follows directly from the hold-and-wait condition. With a single process, it is impossible that the hold and wait condition exists.

  • A resource can only be shared in a mutually exclusive manner. It implies that two processes cannot use the same resource simultaneously.

Follow us for latest updates