Top Banner
Termination Detection
27

Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

Dec 18, 2015

Download

Documents

Madeline Blake
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

Termination Detection

Page 2: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

Goal

• Study the development of a protocol for termination detection with the help of invariants.

Page 3: 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– 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

Page 4: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

• 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

Page 5: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

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

Page 6: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

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

Page 7: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

We will consider two algorithms

• Based on the idea of diffusion

• Based on the idea of global snapshot

– We will study these aspects later.

Page 8: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

Approach 1: Dijkstra Scholten

• Assumptions– Initially one process is active– No failures, lost messages etc.

Page 9: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

• 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

Page 10: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

Predicate in Invariant (1)

• The set of active processes form a tree– True in the initial state– Ensure that this remains true during

computation

Page 11: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

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

Page 12: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

Action (1)

P.j = NULL j receives a message from k

P.j = k, j becomes active

Page 13: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

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

Page 14: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

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

Page 15: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

Problem?

• Does not deal with messages.

Page 16: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

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

Page 17: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

Action (3)

• Maintain a variable oc.j that denotes the number of messages that j has sent and are not yet acknowledged

Page 18: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

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

Page 19: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

• The actions on previous slide can be used to implement termination detection.

• Consider second actionj is active j wants to become passive j has no children

oc.j = 0j becomes passive, P.j = NULL

• Is it possible to drop ` j has no children’ from the guard?

Page 20: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

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

Page 21: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

Action (3)

P.j = NULL j receives a message from kP.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 = 0j becomes passive, P.j = NULL; send ack to parent

j is active j receives a message from kSend ack to k

Other simple actions for maintaining oc.j

Page 22: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

Summarizing Approach 1

• Goal– Active processes form a rooted tree

• If process k activates 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.

Page 23: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

Actions

• Passive Active– If j is passive and receives a computation

message from k then• P.j = k

• Become active

Page 24: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

Actions

• Active Active– If j is active and receives a computation

message from l• Send an acknowledgment

Page 25: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

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

Page 26: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

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

Page 27: Termination Detection. Goal Study the development of a protocol for termination detection with the help of invariants.

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.