© Katz, Spring 2007 CS236368 Formal SpecificationsLecture-- Lamport 1 Lamport ’s State Machines Formal Specifications of Complex Systems CS236368 Shmuel.

Slides:



Advertisements
Similar presentations
1 Data Link Protocols By Erik Reeber. 2 Goals Use SPIN to model-check successively more complex protocols Using the protocols in Tannenbaums 3 rd Edition.
Advertisements

Dr. Kalpakis CMSC 621, Advanced Operating Systems. Distributed Mutual Exclusion.
CS 603 Process Synchronization: The Colored Ticket Algorithm February 13, 2002.
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS Fall 2011 Prof. Jennifer Welch CSCE 668 Set 14: Simulations 1.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
CS4231 Parallel and Distributed Algorithms AY 2006/2007 Semester 2 Lecture 6 Instructor: Haifeng YU.
1 Model checking. 2 And now... the system How do we model a reactive system with an automaton ? It is convenient to model systems with Transition systems.
Automatic Verification Book: Chapter 6. What is verification? Traditionally, verification means proof of correctness automatic: model checking deductive:
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,
A Simple Critical Section Protocol There are N concurrent processes P 1,…,P N that share some data. A process accessing the shared data is said to execute.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Chapter 3 The Critical Section Problem
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
1 Formal Methods in SE Qaisar Javaid Assistant Professor Lecture 05.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
CPSC 668Set 14: Simulations1 CPSC 668 Distributed Algorithms and Systems Spring 2008 Prof. Jennifer Welch.
1 Complexity of Network Synchronization Raeda Naamnieh.
© Katz, 2007CS Formal SpecificationsLecture - Temporal logic 1 Temporal Logic Formal Specifications CS Shmuel Katz The Technion.
CS 582 / CMPE 481 Distributed Systems
© Katz, 2003 Formal Specifications of Complex Systems-- Real-time 1 Adding Real-time to Formal Specifications Formal Specifications of Complex Systems.
Ordering and Consistent Cuts Presented By Biswanath Panda.
Course Summary. © Katz, 2003 Formal Specifications of Complex Systems-- Real-time 2 Topics (1) Families of specification methods, evaluation criteria.
© Katz, Spring 2004 CS Formal SpecificationsLecture-- Lamport 1 Lamport ’s State Machines Formal Specifications of Complex Systems CS Spring.
© Katz, Spring 2004 CS Formal SpecificationsLecture-- Lamport 1 Lamport (cont.): A Lossy Queue Exactly like a regular one, but with one more allowed.
Katz Formal Specifications Larch 1 Algebraic Specification and Larch Formal Specifications of Complex Systems Shmuel Katz The Technion.
מפרטים פורמאליים תירגול מספר 10 מפרטים פורמאליים - תירגול שחר דג Lamport - רק התורים מבוסס על המאמר: “specifying concurrent program modules” by Leslie.
Concurrency CS 510: Programming Languages David Walker.
© Katz, 2007 Formal Specifications of Complex Systems-- Real-time 1 Adding Real-time to Formal Specifications Formal Specifications of Complex Systems.
Concurrency in Distributed Systems: Mutual exclusion.
Course Summary. © Katz, 2007 Formal Specifications of Complex Systems-- Real-time 2 Topics (1) Families of specification methods, evaluation criteria.
Lecture 12 Synchronization. EECE 411: Design of Distributed Software Applications Summary so far … A distributed system is: a collection of independent.
1 Thread Synchronization: Too Much Milk. 2 Implementing Critical Sections in Software Hard The following example will demonstrate the difficulty of providing.
Formal Model for Simulations Instructor: DR. Lê Anh Ngọc Presented by – Group 6: 1. Nguyễn Sơn Hùng 2. Lê Văn Hùng 3. Nguyễn Xuân Hậu 4. Nguyễn Xuân Tùng.
CS4231 Parallel and Distributed Algorithms AY 2006/2007 Semester 2 Lecture 3 (26/01/2006) Instructor: Haifeng YU.
Automatic Verification of Finite-State Concurrent Systems Using Temporal Logic Specifications 1.
Lecture 6-1 Computer Science 425 Distributed Systems CS 425 / ECE 428 Fall 2013 Indranil Gupta (Indy) September 12, 2013 Lecture 6 Global Snapshots Reading:
THIRD PART Algorithms for Concurrent Distributed Systems: The Mutual Exclusion problem.
Reading and Writing Mathematical Proofs Spring 2015 Lecture 4: Beyond Basic Induction.
DISTRIBUTED ALGORITHMS AND SYSTEMS Spring 2014 Prof. Jennifer Welch CSCE
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
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.
Network Protocols Network Systems Security Mort Anvari.
CSCE 715: Network Systems Security Chin-Tser Huang University of South Carolina.
Winter 2007SEG2101 Chapter 111 Chapter 11 Implementation Design.
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.
CS533 – Spring Jeanie M. Schwenk Experiences and Processes and Monitors with Mesa What is Mesa? “Mesa is a strongly typed, block structured programming.
Program Correctness. The designer of a distributed system has the responsibility of certifying the correctness of the system before users start using.
From Natural Language to LTL: Difficulties Capturing Natural Language Specification in Formal Languages for Automatic Analysis Elsa L Gunter NJIT.
CSE 486/586 CSE 486/586 Distributed Systems Global States Steve Ko Computer Sciences and Engineering University at Buffalo.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
1 Chapter 11 Global Properties (Distributed Termination)
Mutual Exclusion Algorithms. Topics r Defining mutual exclusion r A centralized approach r A distributed approach r An approach assuming an organization.
Hwajung Lee. Mutual Exclusion CS p0 p1 p2 p3 Some applications are:  Resource sharing  Avoiding concurrent update on shared data  Controlling the.
Introduction to distributed systems description relation to practice variables and communication primitives instructions states, actions and programs synchrony.
Process Synchronization Presentation 2 Group A4: Sean Hudson, Syeda Taib, Manasi Kapadia.
CSC 1010 Programming for All Lecture 5 Functions Some material based on material from Marty Stepp, Instructor, University of Washington.
Tutorial 2: Homework 1 and Project 1
March 21, 2001 Recall we have talked about the Sliding Window Protocol for Flow Control Review this protocol A window of size I can contain at most I.
PROTOCOL CORRECTNESS Tutorial 3 Theoretical
CS 352 Introduction to Logic Design
Formal Specifications for Complex Systems (236368) Tutorial #10
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS
ITEC452 Distributed Computing Lecture 5 Program Correctness
ITEC452 Distributed Computing Lecture 7 Mutual Exclusion
Presentation transcript:

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 1 Lamport ’s State Machines Formal Specifications of Complex Systems CS Shmuel Katz The Technion titleBoth on mastertitleBoth on master

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 2 Specifying Concurrent Modules Classic paper by Leslie Lamport, ACM TOPLAS, vol. 5, no. 2, 1983 Texual, parametric state machine Insight on overlapping, interference For concrete program unit, like input/output interface, but reactive assumes sequential data structures

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 3 Open versus Closed systems A Closed system has all components inside the specification, and a simple interface to an Environment An Open system has “unknown” assignments, messages, events at any time. Much harder to specify and show correct, but sometimes necessary. When do operations take effect?

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 4 Overlapping Can Be Tricky Initially x = 0 Execute x := x+1 in parallel with x:= x+2. What are the possible results? The answer can depend on what is considered ‘atomic’ Many systems today have multiple processes (sometimes with time sharing)

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 5 Shared Memory Concurrency Multiple processes that change the same variables (operate over the same state) Have to consider what happens DURING an implementation....input/output is not enough. New issues: > waiting, > deadlock, > mutual exclusion, > starvation

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 6 Basic set-up Have sets of atomic actions First part--for safety properties Later--temporal logic for liveness Get values of a state from State Functions, that take the state to a value. x:S --> V and at(c) are state functions. Since the domain is always the state, just write f:R where R is the range

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 7 Parts of a Spec. State functions f1: R1, f2: R2,... Initial conditions I1, I2,... Properties P1, P2,.... If the initial state satisfies the initial conditions, all subsequent states satisfy the properties Pi, when examined through the state functions f j. If Pi is a regular logic predicate, asserts that it is an invariant of the system.

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 8 Other ways of writing Pi A leaves unchanged f when Q >A: a set of actions >f: a state function >Q: a predicate >Means: if a is in A, and Q(s), s---> s’ then f(s ’) = f(s) TOP leaves unchanged stack >TOP is a set of actions, stack is a state function INREAR leaves unchanged front when ~empty

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 9 Allowed Changes allowed changes to g1 when Q1 g2 when Q2 A1: R1 --> S Am: Rm --> Sm >gi: state functions, Qi: predicates >Ai: set of actions, Ri: predicate >Si: binary function on s, s’ pairs for any a taking s to s’, if Qi(s) and gi(s’) =/= gi(s), then for some j, a is in Aj, Rj(s), and Sj(s, s’ )

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 10 Allowed Changes (cont.) “If it changes, it does so in one of these ways....” Does not force change--for safety only Assume that the condition for activating is made false by the change, so we won ’t just keep repeating the same action. Use f and f’ instead of f(s) and f(s’) Assume gj’ = gj if gj’ is not in Si allowed changes to stack POP: | stack| > 0 --> stack = out’  stack’

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 11 Procedures and Parameter Passing (see handout) Modules with procedures Can have several procedures active at once, but only one copy of each. Parameters are passed in a global variable (on purpose to show problems) SUB is in MOD, calls are from outside MOD SUB.PAR : state function for the parameter at(SUB) = control is at beginning of SUB after(SUB) = control just after last of SUB in(SUB) = control is in SUB (including at the beginning, but NOT the exit point)

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 12 module SQ with sub SQUARE All of SUB with SQUARE substituted state function val: Integer at(SQUARE) ==> val = SQUARE.PAR after(SQUARE) ==> SQUARE.PAR = val  2 unchanged val when in(SQUARE) (Above are safety properties only-- need separate guarantee of progress/ liveness)

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 13 Summary on Lamport’s approach For Open Systems where unknown processes can change the system (see queue in handout) The notation restricts which changes are allowed, while still allowing concurrency The notation is only to restrict what is possible—so only relates to safety properties Liveness is added using Temporal Logic This approach can be used to specify Fault Tolerance—will see next… “leaves unchanged” and “allowed changes” are awkward, but typical for safely properties

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 14 Lamport (cont.): A Lossy Queue Exactly like a regular one, but with one more allowed change: queue = Q --> queue’ < Q (could have written queue’ < queue) < means “ is a subsequence of” Problem: the liveness property of GET [] ( (in (GET) /\ |queue| > 0 => <> after(GET)) is now too strong (can ’t really implement)

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 15 A Compromise No liveness constraint on GET leads to a useless lossy queue. Always finishing if there is an element is too demanding. Suggested compromise: [](in(GET)/\ [] <> |queue| > 0 => <>after(GET)) If the queue repeatedly is nonempty, eventually the GET will finish.

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 16 A Channel is a Lossy Queue Replace PUT by TMT (transmit) Replace GET by RCV (receive) The TMT protocol will be in one computer and the RCV in another, with the new allowed transition modeling the possible fault of losing a message in transmission.

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 17 A Key Property In a lossy queue, if we keep transmitting the same message, it will get through! [](( [] <> in(TMT) /\ []( at(TMT) => TMT.PAR = msg) /\ [] <> in(RCV)) => after (RCV) /\ RCV.PAR = msg ) Can’t be stuck in RCV, because then the queue must be empty, contradicting the liveness of TMT. Thus exit RCV repeatedly, and each time remove an element. Must get to msg eventually.....

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 18 Implementing Fault Tolerance A reliable channel: specified by original queue with SEND for PUT and RECEIVE for GET Problem: Implement a reliable channel by imposing a Communication Protocol on two lossy queues. (code given in the tirgul) Example here: alternating bit protocol Sender module has SEND routine activated by user, and uses MTMT and ARCV. Receive module has RECEIVE routine, uses MRCV and ATMT.

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 19 Hints to Understanding squeue has the values SENT that have not yet been moved across the lossy channel. rqueue has the values received after crossing the lossy channel, before RECEIVE operations remove them. snum has the bit value currently being sent rnum has the bit value currently being received on the other side.

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 20 Hints (continued) Keep sending the same (bit, value) pair until you get back an ACK with that bit, then switch your bit and start sending the new bit with the next value. When you get a pair with a new bit put the value in the local rqueue, switch your bit and send an ACK back. Ignore additional copies with the same bit you have, but send back more ACKs with your bit. Initially, the bits are different on each side.

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 21 The Mapping Key to understanding: queue == if snum =/= rnum then rqueue ^ squeue else rqueue ^ tail (squeue) The mapping changes whenever snum or rnum changes-- but the RESULT of the mapping will stay the same! (check cases where that happens) SEND and RECEIVE change the queue TMT and using the lossy implementation do NOT

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 22 Liveness of the queue Need to show that SEND and RECEIVE satisfy the usual queue liveness properties Therefore, need that elements move across the lossy queue, so squeue has room, and rqueue can provide elements when queue has room/ isn’t empty (resp.) Use reasoning by contradiction on the temporal properties.

© Katz, Spring 2007 CS Formal SpecificationsLecture-- Lamport 23 Summary Can model faults as ‘possible changes’ Temporal logic gives global liveness properties not expressed in other ways. Reasoning can be confusing, need care in choosing temporal assertions. Open systems are especially hard to specify and verify, so tools are needed.