Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Resource Deadlocks vs Communication Deadlocks in Distributed Systems
Deadlock in an operating system happens when a process gets into a waiting state as other processes hold the resources which need to be used. This problem generally happens during multi-processing environments, distributed systems, and parallel computation systems.
In distributed systems, deadlocks are considered a major problem, where the resources requested by the process are not available due to other processes holding onto them. A distributed system contains a set of processes p1, p2, p3?pn that do not share a common memory, and communication is made only by passing messages through the network. Each process has two states such as a running state where the process contains all the resources and is ready for execution and a blocked state where the process is in a waiting state needing some resources.
Deadlock Conditions
Below are the four conditions that need to be met for deadlock to occur
Hold and wait One process holds the resources that are needed for another process to use.
Mutual exclusion When only one process is allowed to use one resource at a time.
No preemption No process can be preempted until it completes the execution of a task.
Circular wait The process needs to wait for the required resource in a cyclic manner, where the last process in the queue waits for the resource used by the first process.
Resource Deadlock
Resource deadlock occurs when a process is waiting for a set of resources that is held by another process and it waits to receive all the resources requested before it becomes unblocked. The process set which waits for resources is said to be in a resource deadlock state.
Consider an example when two processes P1 and P2 need resources X and Y. In this case, P1 waits for resource Y which P2 holds, and P2, in turn, waits for resource X which P1 is holding. So, in a closed manner, P1 needs resource Y and waits for P2 to release it, and P2 needs X and waits for P1 to release it.
The above figure shows a resource deadlock since each process waits for another process to acquire all the needed sets of resources. Distributed deadlocks are more difficult to handle because resources and processes are distributed and cannot be detected at a common place. Several approaches are used to handle distributed deadlocks such as detection, prevention, avoidance, and the ostrich algorithm.
Communication Deadlock
Communication deadlock happens among processes which need to communicate and wait for another process for their task. The process which is in a waiting state can unblock itself when it receives communication requests from other processes in the group. When each process in the set waits for another process to communicate, no other process starts communication until it receives further communication from the initial process.
Consider a scenario when process X waits for messages from process Y and process Y in turn waits for messages from another process called Z. Then process Z waits for the initial process X. This deadlock occurs when communication among the processes is locked by each other in a circular manner.
Comparison
| Basis of Difference | Resource Deadlocks | Communication Deadlocks |
|---|---|---|
| Definition | The process waits for several resources that are held by other processes | The process waits for another process in the group to initiate communication |
| Process State | A process waiting for needed resources cannot continue execution until acquiring all of them | The process will not enter execution state until it receives a communication message from another process |
| Waiting For | The process waits for resources to perform its task | The process waits for messages from another process |
| Transaction | No information is known about the dependency between transactions | The process can identify which process to communicate with before beginning the transaction |
| Deadlock Occurrence | When each process in a set needs multiple resources from other processes and cannot unblock itself by fetching the needed resources | When each process waits for communication from another process and no process initiates new communication until it receives the same from the needed process |
| Examples | Process P1 waits for resource X and P2 waits for resource Y, each process holds and waits for the other's resource | Process X waits for a message from process Y, which waits for process Z, and Z waits for initial process X |
Conclusion
Deadlock occurrence in distributed systems is a major issue as resources do not share a common memory location and are distributed among different processes. Two types of deadlocks are possible in distributed systems resource deadlocks and communication deadlocks, each requiring specific detection and resolution strategies for effective system performance.
