DeadLocks in OS

DeadLock

Definition:  A deadlock is a situation where a set of processes are blocked because each process is holding a resource and waiting for some other resource acquired by some other process.

    How does a deadlock occur?


In a multi-programming system, a number of processes compete for a limited number of resources, and if the resource is not available the system enters into a waiting state.

If a process is unable to change its waiting state indefinitely because the resources requested by it are held by another waiting process.

This process is known to be a deadlock.





Events related to Resource allocation:

Request: A process requests a resource through a system call. If the resource is free, the kernel allocates it to the process immediately. otherwise, it changes the state of the process to blocked.

Allocation: The process becomes the holder of the resource allocated to it. The resource state information is updated and the state of the process 

Release: A process releases a resource through a system call. If some processes are blocked on the allocation event of the resource the kernel uses some tie-breaking rule, to decide which process should be allocated the resource.


Conditions for deadlock:

A deadlock occurs if it follows all four conditions:

Non-sharable resources:  Resources cannot be shared. A process needs exclusive access to a resource.

No preemption: A resource cannot be preempted from one process and allocated to another process.

Hold-and-wait: A process continues to hold the resources allocated to it while waiting for another resource.

Circular Waits: A circular chain of hold-and-wait conditions exists in the system. For example Pi waits for Pj, Pj waits for Pk and Pk waits for Pi.


Thank you for reading the blog.

Source: Operating Systems: A Concept-based Approach by  Dhanunjay Dhamdhere.