Open In App

Difference between Resource and Communication Deadlocks in Distributed Systems

Improve
Improve
Like Article
Like
Save
Share
Report

A deadlock occurs when a set of processes requests resources that are already occupied by other processes in the group. Because each process possesses a resource and waits for another resource held by another process, the execution of two or more processes is blocked. 

Four requirements must be met for a deadlock to occur :

  1. Mutual Exclusion –
    At least one resource in the system must be able to be used by only one process at a time.
  2. Hold & Wait –
    There must be a process that retains a resource while waiting for another resource acquired by some other process.
  3. No Preemption –
    It means that resources cannot be taken forcefully from one process and handed over to another.
  4. Circular Wait –
    All processes must wait for the resource in a cyclic fashion, with the last process waiting for the first process’s resource.

Distributed system deadlocks are quite similar to centralized system deadlocks. In centralized systems, we have a single operating system that can manage resource allocation and determine whether there are any deadlocks. It’s more difficult to detect, avoid, and prevent deadlocks when processes and resources are distributed. Dealing with deadlocks can be done in a number of ways :

  1. Ignore – We can choose to ignore the issue. One of the most popular options is this.
  2. Detection – Allowing deadlocks to occur, then detecting that there is a deadlock in the system, and finally dealing with the deadlock.
  3. Prevent – We can impose resource allocation limits to prevent deadlocks.
  4. Avoid – By properly allocating resources, we can eliminate deadlocks.

Deadlock avoidance is not used in distributed systems. The difficulty with deadlock avoidance is that the algorithm will need to know resource use requirements ahead of time in order to correctly schedule them.

Resource Deadlock :
A process can wait for numerous resources at the same time and cannot advance until all of the resources have been acquired. If each process in the set seeks resources held by another process in the set, and it must obtain all the requested resources before it can become unblocked, the process set is resource-deadlocked.

Symbolic Representation –
When Process Pi is waiting to get a resource Ri :

Process Pi is waiting to get a resource Ri

When Process Pi is having a resource Ri :

Process Pi is having a resource Ri

Deadlock Situation: Suppose a system is running 2 processes P1 & P2 and they want the resources R1 & R2. The resource allocation graph is shown below :

Resource Deadlock

Resource Deadlock

Here, P1 owns R1 & waits to get R2 resource while P2 owns R2 & waits to get R1 resource. In this way, P1 waits for P2 to complete & P2 waits for P1 to get complete & hence a deadlock.

Communication Deadlock :
Processes in this deadlock wait to communicate with other processes in a group of processes. On receiving communication from any of these processes, a waiting process can unblock. If each process in the set is waiting to communicate with another process in the set, and no process in the set ever begins any additional communication until it receives the communication for which it is waiting, the set is communication-Deadlocked.

Example –
Process A waits to get a message from process B,  Process B waits to get a message from process C and Process C waits to get a message from process A and hence a deadlock. 
The TFW diagram is shown below : 

Communication Deadlock

Communication Deadlock

Users in a distributed system (DDBS) access the database’s data objects by executing transactions. A transaction can be thought of as a series of reads and writes performed on data objects. A database’s data objects can be thought of as resources that are acquired (through locking) and released (through unlocking) by transactions. In DDBS, a wait-for graph is referred to as transaction-wait-for-graph (TWF Graph)

Difference between Resource and Communication Deadlocks in Distributed Systems :

S. No

Communication Deadlock

Resource Deadlock

1. In the communication model, before a process can continue, it may know the identification of the processes from which it must receive a message to communicate. It is not directly known which transaction is dependent on which other transaction. 
2. In the communication model, a process cannot proceed with the execution until it can communicate with one of the processes for which it is waiting. In the resource allocation model, a process cannot proceed with the execution until it receives all the resources for which it is waiting.
3. Waiting (by processes) is done for messages. Waiting (by processes) is done for resources.
4. If each process in the set is waiting to communicate with another process in the set, and no process in the set ever begins any additional communication until it receives the communication for which it is waiting, the set is communication-Deadlocked. If each process in the set seeks resources held by another process in the set, and it must obtain all the requested resources before it can become unblocked, the process set is resource-deadlocked.
5. Cannot be prevented by a safe state. Can be prevented by a safe state.

Last Updated : 04 Jan, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads