## Silberschatz-Galvin Detection Algorithm

Silberschatz & Galvin (1994) provides the following WFG-based deadlock detection algorithm.
This is a truly distributed deadlock algorithm.

Each site maintains its own local WFG.
This may include some non-local processes that are
• requesting resources held by local processes or
• holding resources needed by local processes.

For example, the local site 1 WFG above shows
• process P3 waiting for a resource held by process P2;
• process P2 waiting for a resource held by process P1; and
• process P2 waiting for a resource held by process P4.
The local site 2 WFG above shows
• process P1 waiting for a resource held by process P3; and
• process P3 waiting for a resource held by process P4.
These do not show which processes are external to sites 1 or 2..

The algorithm expands the local WFGs by adding a node, Pex, to represent the external dependencies.
• An edge, (Pi,Pex), is added if Pi is a local process waiting for a resource at another site.
• An edge, (Pex,Pj), is added if Pj is a process at another site that is waiting for a resource held locally.

In Site 1 of the figure above,
• Edge (P1,Pex) implies that P1 is waiting for a resource at Site 2 that is held by P3.
• Edge (Pex,P3) implies that P3 is a process at Site 2 waiting for a resource that is held by P2 of site 1.

In Site 2 of the figure above,
• Edge (P3,Pex) implies that P3 is waiting for a resource at Site 1.
• Edge (Pex,P1) implies that P1 is a process at Site 1 waiting for a resource that is held by P3 of site 2.

At this point, site 1 recognizes that it has a cycle in its expanded local WFG that contains Pex.
So it sends a deadlock message to site 2, because one of the known external dependencies of site 1 (P3) is on site 2.
This deadlock message contains not the entire WFG for site 1, but just the path for that part of the cycle that does not include Pex.

From this, site 2 updates its expanded local WFG as below:

Since site 2 now finds a cycle in its updated expanded WFG as well, and the process Pex is not in this cycle, deadlock is detected.

If, on the other hand, site 2 can only find a cycle that contains Pex, it would send a deadlock message to whatever other sites were known in its WFG.
It is possible that processes on several sites are involved in a deadlock cycle.

Problem: It is possible that two different sites may determine a cycle about the same time, and both will send a deadlock message to the other (initiating the check for deadlock).
So both sites will update their WFGs, perhaps finding more cycles or more processes involved in the cycles than are really involved in the true global state of the system.