Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 11 Detecting Termination and Deadlocks. Motivation – Diffusing computation Started by a special process, the environment environment sends messages.

Similar presentations


Presentation on theme: "Chapter 11 Detecting Termination and Deadlocks. Motivation – Diffusing computation Started by a special process, the environment environment sends messages."— Presentation transcript:

1 Chapter 11 Detecting Termination and Deadlocks

2 Motivation – Diffusing computation Started by a special process, the environment environment sends messages to some processes Each process is either active or passive passive process can become active only on receiving a message

3 Diffusing computation- Finding the shortest path Problem : find the shortest path from process P 0 to all other processes Each process knows only the delay of its incoming links Process P i maintains:  cost of currently known shortest path to P 0  parent of P i in the shortest path known

4 Diffusing computation- Finding the shortest path Coordinator P 0 starts diffusing computation by sending cost = 0 to neighbors P i on receiving a cost c from P j determines if c + cost(link between P i and P j ) is less than the current cost  If yes: update cost = c and  parent = P j

5 A diffusing algorithm for the shortest path public class ShortestPath extends Process { int parent = -1; int cost = -1; int edgeWeight[] = null; public ShortestPath(Linker initComm, int initCost[]) { super(initComm); edgeWeight = initCost; } public void initiate() { if (myId == Symbols.coordinator) { parent = myId; cost = 0; sendToNeighbors("path", cost); } public synchronized void handleMsg(Message m, int source, String tag) { if (tag.equals("path")) { int dist = m.getMessageInt(); if ((parent == -1) || (dist + edgeWeight[source] < cost)) { parent = source; cost = dist + edgeWeight[source]; System.out.println("New cost is " + cost); sendToNeighbors("path", cost); } }

6 Dijkstra and Scholten’s Algorithm A process is in a green state if it is passive and all its outgoing channels are empty, otherwise, it is in a red state. The computation has terminated if all processes are green

7 Dijkstra and Scholten’s Algorithm Maintain a set T such that  I0: All red processes are part of T Initially only the environment P e 2 T If P j turns P k red and P k was not in T then add P k to T Maintain a directed graph (T,E) on set T such that if P k was added to T due to P j then add an edge from P j to P k (P j s the parent of P k )  I1: The edges E form a spanning tree rooted at P e Remove P k from T and the edge to P k from E only if P k is a green leaf node

8 An Optimization To detect if channel is empty (to determine if the process is green) we could send a signal message (acknowledgements) for every message received Optimization: A node does send the signal message to the process that made it active until it is ready to leave the tree

9 public class DSTerm extends Process implements TermDetector { int state = passive; int D = 0; int parent = -1; boolean envtFlag;... public synchronized void handleMsg(Msg m, int src, String tag) { if (tag.equals("signal")) { D = D - 1; if (D == 0) { if (envtFlag) System.out.println("Termination Detected"); else if (state == passive) { sendMsg(parent, "signal"); parent = -1; } } } else { // application message state = active; if ((parent == -1) && !envtFlag) { parent = src; } else sendMsg(src, "signal"); } } public synchronized void sendAction() { D = D + 1; } public synchronized void turnPassive() { state = passive; if ((D == 0) && (parent != -1)) { sendMsg(parent, "signal"); parent = -1; } } }

10 Termination detection without Acknowledgements Token based algorithm Each process maintains  state: active or passive.  color: black / white white - it has not received any message since the last visit of the token  c: number of messages sent by the process minus the number of messages received

11 Termination detection without Acknowledgements Token  color: Records if the token has seen any black process  count: Records the sum of all c variables in a round A process P 0 is responsible for detecting termination  System has terminated if (color P 0 is white) and (it is passive) and (token is white) and (count + value c at P 0 = 0)

12 Locally Stable Predicates A local predicate B is locally stable if no process involved in the predicate can change its state relative to B once B holds  E.g. Predicate “the distributed computation has terminated”  E.g. A stable predicate which is not locally predicate : “There is at most one token in the system” (if generation of new tokens is not possible in the system)

13 Consistent Interval Computation of a consistent global state is not necessary for locally stable predicates Consistent interval:  An interval [X,Y] is a pair of cuts X,Y such that X µ Y  An interval of cuts [X,Y] is consistent if there exists a consistent cut G such that X µ G µ Y  An interval is consistent iff

14 Algorithm outline Repeatedly compute consistent intervals [X,Y]  If a predicate is true in cut Y and  The values of the variables in predicate B have not changed during the interval Then B is true (though X,Y may be inconsistent cuts)

15 Application : Deadlock Detection Model the system as a wait for graph (WFG), if P i waits for P j then there is an edge from P i to P j If the WFG has a cycle then we have a deadlock Each P i maintains  its WFG and  a bit changed i which records if its WFG has changed since the last report to the coordinator

16 Application : Deadlock Detection (Contd.) Coordinator P_0 requests report periodically from all processes  P_i send its WFG if changed_i is true otherwise it send the message notChanged_i If the combined WFG has a cycle P_0 requests reports from all processes again  If everyone sends notChanged then a deadlock is detected


Download ppt "Chapter 11 Detecting Termination and Deadlocks. Motivation – Diffusing computation Started by a special process, the environment environment sends messages."

Similar presentations


Ads by Google