Representing distributed algorithms Why do we need these? Don’t we already know a lot about programming? •We need to capture the notions of atomicity, non-determinism, fairness etc. •The program should be concise
Syntax & semantics: guarded actions <guard G> → <action A> is equivalent to if G then A Motivation: think message passing or event based systems
Syntax & semantics: guarded actions • Sequential actions S0; S1; S2; . . . ; Sn • Alternative constructs if . . . . . . . . . . fi • Repetitive constructs do . . . . . . . . . od The specification is useful for representing abstract algorithms, not executable codes.
Syntax & semantics Alternative construct G 1 S 1 if G 2 S 2 … G n S n fi When no guard is true, skip (do nothing). When multiple guards are true, the choice of the action to be executed is completely arbitrary (or non- deterministic) .
Syntax & semantics Repetitive construct •For most programs, we G 1 S 1 do will utilize this construct. G 2 S 2 •For brevity, we will . omit do/od G n S n od Keep executing the actions until all guards are false and the program terminates. When multiple guards are true, the choice of the action is arbitrary.
Example: graph coloring ∃ j ∈ neighbor(i): c(j) = c(i) → 1 0 c(i) := 1-c(i) 0 Will the computation terminate? 1
Example: graph coloring continued Instead of writing ∃ j ∈ neighbor(i): c(j) = c(i) → c(i) := 1-c(i) We will write c(j) = c(i) → c(i) := 1-c(i)
An example program uncertain; define x : integer; initially x = 0 do x < 4 x := x + 1 x = 3 x := 0 od Question. Will the program terminate? (Here fairness becomes an important issue)
The adversary A distributed computation can be viewed as a game between the system and an adversary. The adversary comes up with feasible schedules to challenge the system, and a correct algorithm must have an adequate response to meet the challenge.
Non-determinism Non-determinism is abundant in the real world. Token server Determinism is a special case of non-determinism. (Program for a token server - it has a single token} repeat if (req1 and token) then give the token to client1 else if (req2 and token) then give the token to client2 3 1 else if (req3 and token) then give the token to 2 client3 forever Now, assume that all three requests are sent simultaneously. Client 1 always gets the token!
Atomicity (or granularity) Atomic = all or nothing Atomic actions = indivisible actions → x:= 0 do red {red action} blue → x:=7 {blue x action} od Regardless of how nondeterminism is handled, we would expect The answer depends on atomicity that the value of x will be an
Atomicity {Program for P} define b: boolean initially b = true b send msg m to Q do ¬ empty(R,P) receive msg; b := false od Suppose it takes 15 seconds to R P Q send the message. After 5 seconds, b P receives a message from R. Will it stop sending the remainder of the message? NO.
Fairness Defines the choices or restrictions on the scheduling of actions. No such restriction implies an unfair scheduler. For fair schedulers, the following types of fairness have received attention: – Unconditional fairness – Weak fairness – Strong fairness
Fairness An unfair scheduler may never Program test schedule the second (or the third define x : integer actions). So, x may always be {initial value unknown} equal to zero. do true x : = 0 An unconditionally fair scheduler will eventually give every x = 0 x : = 1 statement a chance to execute x = 1 x : = 2 without checking their eligibility. od (Example: process scheduler in a multiprogrammed OS.)
Weak fairness Program test • A scheduler is weakly fair, define x : integer when it eventually executes {initial value unknown} every guarded action whose do true x : = 0 guard becomes true, and remains true thereafter x = 0 x : = 1 x = 1 x : = 2 • A weakly fair scheduler will od eventually execute the second action, but may never execute the third action . Why?
Strong fairness Program test • A scheduler is strongly fair , define x : integer when it eventually executes {initial value unknown} every guarded action whose do true x : = 0 guard is true infinitely often. x = 0 x : = 1 x = 1 x : = 2 • The third statement will be executed under a strongly fair od scheduler. Why?
Fairness Requirement for our Class • Most programs considered in our class would utilize weak fairness or unconditional fairness – Weak fairness implies every enabled action is guaranteed to execute at some time – Unconditional fairness gives every action a chance to execute; • If not enabled (disabled) at the time, its execution has no effect. • Why?
Recommend
More recommend