Deadlock is a situation in a computer system where two or more processes are unable to proceed because each is waiting for the other to release a resource. The Deadlock Prevention and Deadlock Avoidance are two different strategies used to deal with deadlock in operating systems.

Deadlock Prevention

The Deadlock Prevention involves designing the system in such a way that it is impossible for deadlock to occur. This can be achieved by eliminating one of the four necessary conditions for deadlock: mutual exclusion, hold and wait, no preemption, and circular wait. However, this approach may be too restrictive in some situations, as it may limit the functionality of the system.

Deadlock Avoidance

Deadlock avoidance, on the other hand, is a technique used to dynamically ensure that the system does not enter a deadlock state. This is done by predicting the possibility of deadlock and taking preemptive measures to avoid it. The operating system uses various Algorithms to achieve this, such as the Banker’s Algorithm and the Resource Allocation Graph Algorithm.

Banker’s Algorithm

The banker’s algorithm is a deadlock avoidance algorithm that is used to determine whether a request for resources from a process can be granted without causing deadlock. The algorithm works by simulating the allocation of resources to each process and determining whether a safe state can be reached.

In a safe state, it is possible for all processes to complete their execution without entering a deadlock state. The algorithm works by maintaining information about the available resources and the maximum resource needs of each process. When a process requests resources, the algorithm checks whether granting the request would result in a safe state. If it would, the resources are allocated to the process. If not, the request is denied, and the process must wait until the necessary resources become available.

Resource Allocation Graph Algorithm

The banker’s algorithm uses a number of data structures, including an available vector, a matrix of maximum resource needs, a matrix of current resource allocations, and a matrix of resource needs. The algorithm iterates through each process and checks whether its maximum resource needs can be satisfied without causing a deadlock. If a safe state is possible, the resources are allocated to the process, and the algorithm moves on to the next process.

And get notified everytime we publish a new blog post.