ITEC452 Distributed Computing Lecture 5 Program Correctness

Slides:



Advertisements
Similar presentations
CS 267: Automated Verification Lecture 8: Automata Theoretic Model Checking Instructor: Tevfik Bultan.
Advertisements

Partial Order Reduction: Main Idea
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Program correctness The State-transition model A global state S  s 0 x s 1 x … x s m {s k = local state of process k} S0  S1  S2  … Each state transition.
PROTOCOL VERIFICATION & PROTOCOL VALIDATION. Protocol Verification Communication Protocols should be checked for correctness, robustness and performance,
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
CS542 Topics in Distributed Systems Diganta Goswami.
Distributed Computing 5. Snapshot Shmuel Zaks ©
Sept COMP60611 Fundamentals of Parallel and Distributed Systems Lecture 12 The Critical Section problem John Gurd, Graham Riley Centre for Novel.
Distributed Computing 8. Impossibility of consensus Shmuel Zaks ©
Lecture 2: Reasoning with Distributed Programs Anish Arora CSE 6333.
CSE115/ENGR160 Discrete Mathematics 04/12/11 Ming-Hsuan Yang UC Merced 1.
Lecture 3-1 Computer Science 425 Distributed Systems Lecture 3 Logical Clock and Global States/ Snapshots Reading: Chapter 11.4&11.5 Klara Nahrstedt.
Distributed Computing 5. Snapshot Shmuel Zaks ©
Representing distributed algorithms Why do we need these? Don’t we already know a lot about programming? Well, you need to capture the notions of atomicity,
Concurrency. A process is a program executing on a virtual computer Processor speed and multiplexing of shared resources are ignored Order of thread execution.
The Complexity of Distributed Algorithms. Common measures Space complexity How much space is needed per process to run an algorithm? (measured in terms.
Program correctness The State-transition model The set of global states = so x s1 x … x sm {sk is the set of local states of process k} S0 ---> S1 --->
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Global States Steve Ko Computer Sciences and Engineering University at Buffalo.
Program correctness The State-transition model A global states S  s 0 x s 1 x … x s m {s k = set of local states of process k} S0  S1  S2  Each state.
Hwajung Lee. The State-transition model The set of global states = s 0 x s 1 x … x s m {s k is the set of local states of process k} S0  S1  S2  Each.
Defining Liveness by Bowen Alpern and Fred B. Schneider Presented by Joe Melnyk.
More on Correctness. Prime Factorization Problem: Write a program that computes all the prime factors of a given number Solution (Idea): Factors are less.
CIS 842: Specification and Verification of Reactive Systems Lecture INTRO-Examples: Simple BIR-Lite Examples Copyright 2004, Matt Dwyer, John Hatcliff,
Hwajung Lee. The State-transition model The set of global states = s 0 x s 1 x … x s m {s k is the set of local states of process k} S0  S1  S2  Each.
Physical clock synchronization Question 1. Why is physical clock synchronization important? Question 2. With the price of atomic clocks or GPS coming down,
Hwajung Lee. Well, you need to capture the notions of atomicity, non-determinism, fairness etc. These concepts are not built into languages like JAVA,
Hwajung Lee. Why do we need these? Don’t we already know a lot about programming? Well, you need to capture the notions of atomicity, non-determinism,
ITEC452 Distributed Computing Lecture 6 Mutual Exclusion Hwajung Lee.
Hwajung Lee. Mutual Exclusion CS p0 p1 p2 p3 Some applications are:  Resource sharing  Avoiding concurrent update on shared data  Controlling the.
Hwajung Lee. Mutual Exclusion CS p0 p1 p2 p3 Some applications are: 1. Resource sharing 2. Avoiding concurrent update on shared data 3. Controlling the.
1 CSEP590 – Model Checking and Automated Verification Lecture outline for July 9, 2003.
CIS 720 Lecture 5. Techniques to avoid interference Disjoint variables –If the write set of each process is disjoint from the read and write set of other.
Fault tolerance and related issues in distributed computing Shmuel Zaks GSSI - Feb
Model Checking Lecture 1. Model checking, narrowly interpreted: Decision procedures for checking if a given Kripke structure is a model for a given formula.
Ordering of Events in Distributed Systems UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department CS 739 Distributed Systems Andrea C. Arpaci-Dusseau.
Program Correctness. The designer of a distributed system has the responsibility of certifying the correctness of the system before users start using.
Software Systems Verification and Validation Laboratory Assignment 4 Model checking Assignment date: Lab 4 Delivery date: Lab 4, 5.
Presented by: Belgi Amir Seminar in Distributed Algorithms Designing correct concurrent algorithms Spring 2013.
CSE 486/586 CSE 486/586 Distributed Systems Global States Steve Ko Computer Sciences and Engineering University at Buffalo.
ITEC452 Distributed Computing Lecture 15 Self-stabilization Hwajung Lee.
Model Checking Lecture 1: Specification Tom Henzinger.
Hwajung Lee. Mutual Exclusion CS p0 p1 p2 p3 Some applications are:  Resource sharing  Avoiding concurrent update on shared data  Controlling the.
Agenda  Quick Review  Finish Introduction  Java Threads.
Introduction to distributed systems description relation to practice variables and communication primitives instructions states, actions and programs synchrony.
Proof of liveness: an example
Model and complexity Many measures Space complexity Time complexity
Lecture 3: State, Detection
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS
Hwajung Lee ITEC452 Distributed Computing Lecture 8 Representing Distributed Algorithms.
Self-stabilization.
ITEC452 Distributed Computing Lecture 9 Global State Collection
Copyright © Cengage Learning. All rights reserved.
Alternating Bit Protocol
Atomicity, Non-determinism, Fairness
Presented By: Raquel Whittlesey-Harris 12/04/02
Mutual Exclusion Problem Specifications
ITEC452 Distributed Computing Lecture 7 Mutual Exclusion
Mutual Exclusion CS p0 CS p1 p2 CS CS p3.
Semaphores Chapter 6.
MA/CSSE 474 More Math Review Theory of Computation
Axiomatic Verification II
Abstraction.
Chapter 5 (through section 5.4)
Physical clock synchronization
ITEC452 Distributed Computing Lecture 7 Mutual Exclusion
CIS 720 Lecture 5.
COMP60621 Designing for Parallelism
CIS 720 Lecture 5.
Proof of liveness: an example
Presentation transcript:

ITEC452 Distributed Computing Lecture 5 Program Correctness Hwajung Lee ITEC452 Distributed Computing Lecture 5 Program Correctness

Program correctness The State-transition model The set of global states = s0 x s1 x … x sm {sk is the set of local states of process k} S0  S1  S2  Each transition is caused by an action of an eligible process. We reason using interleaving semantics transition state action action action Initial state We want to check if the program could arrive at one of the final states.

Correctness criteria Safety properties Liveness properties Bad things never happen Liveness properties Good things eventually happen

Example 1: Mutual Exclusion Process 0 Process 1 do true  do true  Entry protocol Entry protocol Critical section Critical section Exit protocol Exit protocol od od Safety properties (1) There is no deadlock (2) At most one process enters the critical section. Liveness property A process trying to enter the CS must eventually succeed. (This is also called the progress property) CS CS

Testing vs. Proof Testing: Apply inputs and observe if the outputs satisfy the specifications. Fool proof testing can be painfully slow, even for small systems. Most testing are partial. Proof: Has a mathematical foundation, and a complete guarantee. Sometimes not scalable.

Correctness proofs Since testing is not a feasible way of demonstrating the correctness of program in a distributed system, we will use some form of mathematical reasoning as follows: Assertional reasoning of proving safety properties Use of well-founded sets of proving liveness properties Programming logic Predicate transformers

Review of Propositional Logic Example: Prove that P P V Q Pure propositional logic is sometimes not adequate for proving the properties of a program, since propositions can not be related to program variables or program state. Yet, an extension of propositional logic, called predicate logic, will be used for proving the properties.

Review of Predicate Logic Predicate logic is an extension of propositional logic cf. A proposition is a statement that is either true or false. A predicate specifies the property of an object or a relationship among objects. A predicate is associated with a set, whose properties are often represented using the universal quantifier .(for all) and the existential quantifier. (there exists). <quantifier><bound variable(s)>:<range>::<property> (ex)  j: j  N(i) :: c[j] = c[i] +1 mod 3

Examples of Safety invariant Well-known synchronization problems Invariant means: a logical condition which should always be true. 1. The mutual exclusion problem. NCS ≤ 1, where NCS is the Total number of processes in CS at any time 2. Producer-consumer problem. 0 ≤ NP - NC ≤ buffer capacity (NP = no. of items produced, NC = no. of items consumed) 3. Partial correctness: The bad thing here is the possibility of the program terminating with a wrong answer or entering into a deadlock. producer consumer buffer

Exercise What can be a safety invariant for the readers and writers problem? Only one write can write to the file at a time. When a writer write to the file, no process can read. Many processes can read at the same time. Let NW denote the number of writer processes updating the file and NR denote the number of reader processes reading the file.  ((NW = 1) Λ (NR=0)) V ((NW =0) Λ (NR≥0)) Only one write can write to the file at a time. When a writer write to the file, no process can read. Many processes can read at the same time.

Assertional reasoning of proving safety properties (1) n1= # of messages in c1 n2= # of messages in c2 define c1, c2 : channel; {init c1 =  c2 =} r, t : integer; {init r = 5, t = 5} {program for T} 1 do t > 0 send msg along c1; t := t -1 2  ¬empty (c2)  rcv msg from c2; t := t + 1 od {program for R} 3 do ¬empty (c1)  rcv msg from c1; r := r+1 4  r > 0  send msg along c2; r := r-1 We want to prove the safety property P: P  n1 + n2 ≤ 10 transmitter receiver

Assertional reasoning of proving safety properties (2) n1, n2 = # of msg in c1and c2 respectively. We will establish the following invariant: I  (t ≥ 0)  (r ≥ 0)  (n1 + t + n2 + r = 10) (I implies P). Check if I holds after every action. {program for T} 1 do t > 0 send msg along c1; t := t -1 2  ¬empty (c2)  rcv msg from c2; t := t+1 od {program for R} 3 do ¬empty (c1)  rcv msg from c1; r := r+1 4  r > 0  send msg along c2; r := r-1 Use the method of induction

Liveness properties Eventuality is tricky. There is no need to guarantee when the desired thing will happen, as long as it happens.

Type of Liveness Properties Progress Properties If the process want to enter its critical section, it will eventually do. No deadlock? Reachability Properties : The question is that St is reachable from S0? The message will eventually reach the receiver. The faulty process will be eventually be diagnosed Fairness Properties : The question is if an action will eventually be scheduled. Termination Properties The program will eventually terminate.

Proving liveness Use of well-founded sets of proving liveness properties Global state Global state If there is no infinite chain like w1 ] w2 ] w3 ] w4 ..., i.e. If an action changes the system state from s1 to s2 f(si) ] f(si+1) ] f(si+2) ... S1 S2  S3  S4   f  f  f  f w1 w2 w3 w4 w1, w2, w3, w4  WF WF is a well-founded set whose elements can be ordered by ] then the computation will definitely terminate! f is called a measure function

Proof of liveness: an example c[0] Clock phase synchronization System of n clocks ticking at the same rate. Each clock is 3-valued, i,e it ticks as 0, 1, 2, 0, 1, 2… A failure may arbitrarily alter the clock phases. The clocks need to return to the same phase. c[1] c[2] c[3] c[n-1]

Proof of liveness: an example c[k]  {0,1,2} Clock phase synchronization {Program for each clock} (c[k] = phase of clock k, initially arbitrary) do  j: j  N(i) :: c[j] = c[i] +1 mod 3  c[i] := c[i] + 2 mod 3   j: j N(i) :: c[j] ≠ c[i] +1 mod 3  c[i] := c[i] + 1 mod 3 od Show that eventually all clocks will return to the same phase (convergence), and continue to be in the same phase (closure) c[0] c[1] c[2] c[3] c[n-1]

Proof of convergence Let D = d[0] + d[1] + d[2] + … + d[n-1] d[i] = 0 if no arrow points towards clock i; = i + 1 if a pointing towards clock i; = n – i if a  pointing towards clock i; = 1 if both  and point towards clock i. By definition, D ≥ 0. Also, D decreases after every step in the system. So the number of arrows must reduce to 0. D= 0 means all the clocks are synchronized. 2 2 2 1 1 1 1 2 2 2 2 2 Understand the game of arrows