280 likes | 437 Views
Termination Detection. Goal. Study the development of a protocol for termination detection with the help of invariants. Termination Detection. Rules: A process is either active or passive An active process can become passive at any time
E N D
Goal • Study the development of a protocol for termination detection with the help of invariants.
Termination Detection • Rules: • A process is either active or passive • An active process can become passive at any time • A passive process can become active only if it receives an computation message • Only active processes can send computation messages. All processes can receive them
A system is said to be terminated if • All processes are passive • No application messages are in transit • We distinguish between computation messages and messages sent for detecting termination. Any process can send and receive them. These messages do not change the status of a process
Application • A solution for termination detection allows one to ensure that all tasks in a system are indeed complete, even though the tasks may create additional tasks that are run at other processors in the system
Observation • Termination detection is a stable property • Once true, it remains true forever • Detecting such properties is important for many problems including • Garbage collection • Deadlock detection
We will consider two algorithms • Based on the idea of diffusion • Based on the idea of global snapshot • We will study these aspects later.
Approach 1: Dijkstra Scholten • Assumptions • Initially one process is active • No failures, lost messages etc.
Each process j maintains a variable P.j that is its parent in the tree • At root, P.root = root • Initially for all other processes, • P.j = NULL
Predicate in Invariant (1) • The set of active processes form a tree • True in the initial state • Ensure that this remains true during computation
When a Process becomes active • Consider the case when j changes from Passive to Active • It must be the case that j received a computation message from some process, say k • P.j = k • Become active
Action (1) P.j = NULL j receives a message from k P.j = k, j becomes active
When a Process Becomes Passive • Consider the case when j changes from Active to Passive • It must be the case that j has no children
Action (2) P.j = NULL j receives a message from k P.j = k, j becomes active j is active j wants to become passive j has no children j becomes passive, P.j = NULL
Problem? • Does not deal with messages.
Predicate in Invariant (2) • The set of active processes form a tree • If j is passive then all messages it sent have been received • True initially • Preserve this predicate during computation
Action (3) • Maintain a variable oc.j that denotes the number of messages that j has sent and are not yet acknowledged
Action (2) corrected P.j = NULL j receives a message from k P.j = k, j becomes active j is active j wants to become passive j has no children oc.j = 0 j becomes passive, P.j = NULL
The actions on previous slide can be used to implement termination detection. • Consider second action j is active j wants to become passive j has no children oc.j = 0 j becomes passive, P.j = NULL • Is it possible to drop ` j has no children’ from the guard?
Answer • We could if we guarantee that • oc.j = 0 j has no children • Same as • j has children oc.j > 0 • Could be achieved if the child does not respond to at least one of parent’s message (first one?) • Thus, checking oc.j is 0 sufficient
Action (3) P.j = NULL j receives a message from k P.j = k, j becomes active(Don’t send ack to this message) j is active j wants to become passive j has no children oc.j = 0 j becomes passive, P.j = NULL; send ack to parent j is active j receives a message from k Send ack to k Other simple actions for maintaining oc.j
Summarizing Approach 1 • Goal • Active processes form a rooted tree • If process kactivates j then j sets its parent to k • If a process is passive, all messages it sent have been received • Acknowledge each message (at some time) • A process becomes passive only when all its children are passive; in other words, force a process to wait for its children to become passive. • This is achieved if the children do not send an acknowledgment for the first message received from the parent until they become passive.
Actions • Passive Active • If j is passive and receives a computation message from k then • P.j = k • Become active
Actions • Active Active • If j is active and receives a computation message from l • Send an acknowledgment
Actions • Message send • If j wants to send message (it must be active) • oc.j ++ • (Number of outstanding acknowledgments is increased) • Acknowledgement receive • oc.j = oc.j – 1
Actions • Active passive • If j wants to be passive and oc.j = 0 • Send an acknowledgment to P.j (Observe that the first message from parent was not immediately acknowledged) • Become passive • If j is the root then declare termination
Diffusing Computation • Crucial for various applications • General outline • root(?) sends the diffusion message • Every node that receives the diffusion message for the first time forwards it to its neighbors • First node from which diffusion is received is called parent • All subsequent diffusion messages are acknowledged • Upon receiving acknowledgements form all neighbors, a node completes the diffusion and sends acknowledgment to parent • When root completes the diffusion, the diffusion computation is complete • We will see application of diffusion computation later in the class.