What is Deadlock and Wait for Graph


Definition 1: A deadlock occurs when the first transaction has locks on the resources that the second
transaction wants to modify, and the second transaction has locks on the resources that the first transaction intends to modify.

Definition 2: Deadlock is a condition where multiple processes are blocked by one another because one process is holding a resource and waiting for another resource acquired by some other process.

consider the diagram Process 1 waiting for process 2, and process 2 is waiting for process 3 thus all are in circular wait which cause deadlock.

Example of Dead Lock

Deadlock Example 1:
Consider, when two buses moving toward each other on same track and here is only 1 track, none of the bus because they are in-front of each other.

Similar condition occurs in operating systems when there are two or more processes hold some resources and wait for resources held by other(s).  For example, in the below diagram, Process 1 is holding Resource 1 and waiting for resource 2 which is acquired by process 2, and process 2 is waiting for resource 1.

Deadlock Example 2: 
A simple computer-based example is as follows. Suppose a computer has three CD drives and three processes. Each of the three processes holds one of the drives. If each process now requests another drive, the three processes will be in a deadlock. Each process will be waiting for the "CD drive released" event, which can be only caused by one of the other waiting processes. Thus, it results in a circular chain.  

Wait for Graph

It is used for the detection of deadlock. It consists of nodes and links. The nodes represent transaction, whereas arrowhead represents that a transaction has locked a particular data item.

Post a Comment