In relation to concurrent computing, deadlock refers to a situation in which two or more processes are blocked awaiting another resource that is being held waiting for another one. For instance, if there are two processes: P1 and P2, and each has a resource: R1 and R2, P1 will hold R1, waiting for P2 to release R2. At the same time, P2 will hold R2 until R1 is released; thus, neither of them is releasing any resource (Silberschatz et al., 2018). They are common in multiprocessing systems, parallel computing, and distributed systems. They all use software or hardware locks to adjudicate shared resources and launch process synchronization.
Deadlocks are characterized by four Coffman conditions that lock the operating system. Although they are not mutually exclusive, once they all hold, resource execution fails. They include mutual exclusion, hold and wait, no preemption, and circular wait (Duo et al., 2020). Mutual exclusion is when a single resource can only be used by one process at a time. When the resource is in use, and another process requests it, the requesting process is delayed until its release.
In hold and wait, the process of deadlocks should only access one resource and wait until another process has acquired another resource. No preemption refers to the situation where a process obtaining a particular resource cannot be preempted to ransom the developed resource. Instead, it will release it voluntarily upon completion of the allocated task. All processes are always waiting circularly to receive a resource. Circular wait operates similarly to hold and wait, only that it has a circular pattern. There exists a defined set (P0, P1, …Pn) of allocation of resources (Krogh, 2021). P0 will be waiting for a resource being used by P1. Pn-1 will be awaiting resource that is already allocated to Pn.
Deadlocks can be managed by two main methods, including prevention and avoidance. In some incidents, deadlocks can be ignored as they occur once in a while, and their occurrence may not cause any severe damage and can be resolved by rebooting only. Deadlock prevention can be effective if one of the characteristics is controlled. Elimination of mutual exclusion cannot be entirely achieved as some resources are inherently non-shareable. This could include resources such as printers and tape drives.
Hold and wait is preventable by ensuring a process does not hold any resource while simultaneously trying to obtain another one. All operations can be managed so that the processes request the necessary resources for a particular task once. Before requisition, the process should release all held resources. However, this method may lead to starvation and should therefore be monitored diligently (Duo et al., 2020). Preemption prevention can attain through two approaches. The process can be compelled to delay a request and release all held resources implicitly. Secondly, if the resources required cannot be obtained, the process should seek other procedures regulating the resource and have it preempted. The resource is then included in the list of the process’s resources.
The circular wait is controllable by labelling the resources and having each process request them in order. Such a method could be challenging as it is hard to determine the appropriate order of the resources. Deadlock avoidance presents the idea of the complete elimination of deadlock chances (Silberschatz et al., 2018). This is achievable by preventing one of the characteristics mentioned earlier. A safe resource allocation state should be established where the system can allocate each resource as requested.
References
Duo, W., Jiang, X., Karoui, O., Guo, X., You, D., Wang, S., & Ruan, Y. (2020). A deadlock prevention policy for a class of multithreaded software. IEEE Access, 8, 16676-16688. Web.
Krogh, J. W. (2021). Case Study: Deadlocks. In MySQL Concurrency (pp. 259-275). Apress, Berkeley, CA. Web.
Silberschatz, A., Galvin, P. B., & Gagne, G. (2018). Operating system soncepts (10th ed.). John Wiley & Sons, Inc.