Concurrent Separation Logic

Slides:



Advertisements
Similar presentations
Dataflow Analysis for Datarace-Free Programs (ESOP 11) Arnab De Joint work with Deepak DSouza and Rupesh Nasre Indian Institute of Science, Bangalore.
Advertisements

Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Soundness of Higher-order Frame Rules (How did category theory help me?) Hongseok Yang Seoul National University Joint work with Lars Birkedal and Noah.
Reduction, abstraction, and atomicity: How much can we prove about concurrent programs using them? Serdar Tasiran Koç University Istanbul, Turkey Tayfun.
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.
Formal Semantics of Programming Languages 虞慧群 Topic 6: Advanced Issues.
Goldilocks: Efficiently Computing the Happens-Before Relation Using Locksets Tayfun Elmas 1, Shaz Qadeer 2, Serdar Tasiran 1 1 Koç University, İstanbul,
Verification of Multithreaded Object- Oriented Programs with Invariants Bart Jacobs, K. Rustan M. Leino, Wolfram Schulte.
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
This Week Finish relational semantics Hoare logic Interlude on one-point rule Building formulas from programs.
Program Analysis and Verification
Ashish Kundu CS590F Purdue 02/12/07 Language-Based Information Flow Security Andrei Sabelfield, Andrew C. Myers Presentation: Ashish Kundu
Programming Language Semantics Rely/Guarantee Reasoning Parallel Programs Tal Lev-Ami Viktor Vafeiadis Mooly Sagiv.
On the Relationship Between Concurrent Separation Logic and Assume-Guarantee Reasoning Xinyu Feng Yale University Joint work with Rodrigo Ferreira and.
Local Reasoning Peter O’Hearn John Reynolds Hongseok Yang.
Separation Logic A Logic of Shared Mutable Data Structures John Reynolds CMU Extended subset Mooly Sagiv.
Semaphores, mutexes and condition variables. semaphores Two types – Binary – 0 or 1 – Counting 0 to n Wait – decrements > 0 forces a wait Post or signal.
1 Sharing Objects – Ch. 3 Visibility What is the source of the issue? Volatile Dekker’s algorithm Publication and Escape Thread Confinement Immutability.
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
Operational Semantics Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Programming Language Semantics Axiomatic Semantics of Parallel Programs.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
K. Rustan M. Leino RiSE, Microsoft Research, Redmond joint work with Peter Müller and Jan Smans Lecture 0 1 September 2009 FOSAD 2009, Bertinoro, Italy.
1 Thread Synchronization: Too Much Milk. 2 Implementing Critical Sections in Software Hard The following example will demonstrate the difficulty of providing.
CS510 Concurrent Systems Introduction to Concurrency.
Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:
Runtime Refinement Checking of Concurrent Data Structures (the VYRD project) Serdar Tasiran Koç University, Istanbul, Turkey Shaz Qadeer Microsoft Research,
1 Concurrent Languages – Part 1 COMP 640 Programming Languages.
Concurrency Verification. Why concurrency verification Concurrent programs show in many systems –Multi-task support in OS kernels –Handling interrupts.
© Andrew IrelandDependable Systems Group Cooperative Reasoning for Automatic Software Verification Andrew Ireland School of Mathematical & Computer Sciences.
Rustan Leino RiSE, Microsoft Research, Redmond MIT 5 June 2009 Joint work with: Peter Müller, ETH Zurich Jan Smans, KU Leuven.
11/18/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam.
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 4: Axiomatic Semantics I Roman Manevich Ben-Gurion University.
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.
Separation and Information Hiding Peter W. O’Hearn (Queen Mary, University of London) John C. Reynolds (Carnegie Mellon University) Hongseok Yang (Seoul.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
1 Condition Variables CS 241 Prof. Brighten Godfrey March 16, 2012 University of Illinois.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Synchronization Emery Berger and Mark Corner University.
Lecture 4 Correctness and Fairness Verification and Assurance.
Program Analysis and Verification
CS510 Concurrent Systems Jonathan Walpole. Introduction to Concurrency.
Spring 2017 Program Analysis and Verification
CS703 - Advanced Operating Systems
Formal methods: Lecture
Memory Consistency Models
Memory Consistency Models
Joint work with Yong Li, Xinyu Feng, Zhong Shao and Yu Zhang
What I Teach (Do what I say, not what I do)
CS510 Operating System Foundations
Formal Methods in Software Engineering 1
Verification of Concurrent Programs
Concurrency Verification
Lecture 5 Floyd-Hoare Style Verification
Programming Languages 2nd edition Tucker and Noonan
Parallelism and Concurrency
Separation Logic and Concurrency Verification
Formal Methods in software development
Monitor Giving credit where it is due:
Concurrent Separation Logic
Concurrent Separation Logic
Formal Methods in software development
Non-preemptive Semantics for Data-race-free Programs
CS333 Intro to Operating Systems
Program correctness Axiomatic semantics
Monitors and Inter-Process Communication
Programming Languages 2nd edition Tucker and Noonan
Don Porter Portions courtesy Emmett Witchel
Program Analysis and Verification
Presentation transcript:

Concurrent Separation Logic

How to prove the correctness of concurrent programs? Difficult because of the interleaving and state sharing. Sometimes the programs could be too smart such that they are very difficult to understand.

How to prove the correctness of concurrent programs One philosophy (due to Tony Hoare): Disallow the smart (but error-prone) programs; Concurrent programming should follow some idioms or disciplines. Most of the time each process uses its own private data. In the rare cases that they need to communicate, access the shared data exclusively in critical regions. await (B) do C with r when B do C Mutex or locks (which we will use here)

The language x := e | [e] := e' | x := [e] | cons(e) | dispose(e) | C; C | C || C | … A new construct: l.acq() | l.rel()

Operational Semantics Program state: (s, h, L) where L  locks  {0, 1} L(l) = 1 (l.acq(), (s, h, L))  (skip, (s, h, L{l  0}) ) (l.rel(), (s, h, L))  (skip, (s, h, L{l  1}) )

How to control interference? Basic idea: Each thread has private memory (resource) The private resource can be arbitrarily used Private resources of different threads are disjoint Shared resources are protected by locks Shared resources are disjoint with local resources Can only be used when the lock is acquired (i.e. in critical regions) Different locks protect different resources

Basic Memory Model Shared (accessible only in critical regions) Private Private

Basic Memory Model

Basic Memory Model

Basic Memory Model

Basic Memory Model When the resource is acquired/released, it must be well-formed. The well-formedness is resource invariant.

Concurrent Separation Logic (CSL) Lock-based critical regions (CR): l.acq(); … l.rel() Invariants about memory protected by locks:  = {l1  r1, …, ln  rn} r1, …, rn disjoint l1 ln r1   rn

CSL – Formalization Key ideas: Threads can only access disjoint resources at the same time. p  q p q Transfer is logical: no memory copying ┝ {p1} C1 {q1} ┝ {p2} C2 {q2} ┝ {p1  p2} C1 || C2 {q1  q2}

CSL – Parallel Composition ln p  q p q r1   rn  ┝ {p1} C1 {q1}  ┝ {p2} C2 {q2}  ┝ {p1  p2} C1 || C2 {q1  q2} Transfer is logical: no memory copying I()  p1  p2 I()  q1  q2 We’ll define I() later.

CSL - Locks Lock acquire: Lock release:  ┝ {p} l.acq() {p  (l)} Note: do not support reentrant locks Lock release:  ┝ {p  (l)} l.rel() {p} Compare the rules with cons and dispose

Examples (l) = full  c _, _   full  emp Put (x): l.acq(); while( full ){ l.rel(); } c := x; full := true; Get (y): l.acq(); while( !full ){ l.rel(); } y := c; full := false; (l) = full  c _, _   full  emp

Examples (l) = full  c _, _   full  emp Put (x): l.acq(); while( full ){ l.rel(); } (l) = full  c _, _   full  emp {x _, _ } {x _, _  (l)   full } {x _, _ } c := x; full := true; l.rel(); {x _, _  (l) } {c _, _ } {x _, _ } {full  c _, _ } {x _, _  (l) } {(l) } {emp } {x _, _  (l)   full }

Examples (l) = full  c _, _   full  emp get (y): l.acq(); while( !full ){ l.rel(); } (l) = full  c _, _   full  emp {emp} { (l)  full } {c _, _ } y := c; full := false; l.rel(); { (l) } {y _, _ } { emp } {y _, _  (full  emp) } {(l) } {y _, _  (l)} {y _, _ } {(l)  full }

Examples {x _, _ } put (x) {emp } {emp} get (y) {y _, _ } {emp} x := cons(a, b); put(x); get(y); use(y); dispose(y); {x _, _ } {y _, _ } {y _, _ } {emp } {emp} {emp  emp}

Examples (2) (l) = list(f) alloc (x, a, b): l.acq(); if( f == null ){ l.rel(); x := cons (a, b); } else { x := f; f := [x+1]; [x] := a; [x+1] := b; } free (y): l.acq(); [y+1] := f; f := y; l.rel(); (l) = list(f)

Examples (2)

Requirement on Resource Invariant  ┝ {p1} C1 {q1}  ┝ {p2} C2 {q2}  ┝ {p1  p2} C1 || C2 {q1  q2} l1 ln r1   rn Transfer is logical: no memory copying Resource invariants need to be precise, i.e.  l  dom(). precise( (l) )

Requirement on Resource Invariant one  10  _ (l) = true  ┝ {true} skip {true} ┝ {(emp  one)  true} skip {emp  true}  ┝ {(emp  one)} l.acq; skip; l.rel(); {emp}  C  l.acq; skip; l.rel(); ┝ {(emp  one)} C {emp}  ┝ {(emp  one)} C {emp}  ┝ {emp} C {emp}  ┝ {one} C {emp}  ┝ {emp  one} C {emp  one}  ┝ {one} C {one} 

Requirement on Resource Invariant (l) = true  ┝ {one} C {one}  ┝ {one} C {emp}  ┝ {one} C {one  emp}  ┝ {one} C {false} The problem: (l) is not precise. Recall that p  r  q  r  (p  q )  r does not hold unless r is precise.

Soundness l1 ln I(, L, l) = L(l) = 0  emp  L(l) = 0  (l) r1   rn I(, L) = ldom() . I(, L, l) We define Safek(, (s, h, L), C, q) inductively.

Soundness Safe0(, (s, h, L), C, q) always holds Safek+1(, (s, h, L), C, q) holds if there exist hs and hp such that (1) h = hs |+| hp; (2) (s, hs) |= I(, L) (3) for all s’, hs’, L’, and h’, if (s’, hs’) |= I(, L’), and h = hs’ |+| hp, then Safek(, (s’, h’, L’), C, q) (4) if C = skip, then (s, hp) |= q  true (5) for all s’, h’, L’, if (C, (s, h, L))  (C’, (s’, h’, L’)), then Safek(, (s’, h’, L’), C’, q)

Soundness l1 ln I(, L, l) = L(l) = 0  emp  L(l) = 0  (l) r1   rn I(, L) = ldom() . I(, L, l) We define Safek(, (s, h, L), C, q) inductively. Safe(, (s, h, L), C, q) iff k. Safek(, (s, h, L), C, q) [ ┝ { p } C { q } ] s, h, L. if (s, h) |= I(, L)  p  true, then Safe(, (s, h, L), C, q)

Reading Peter W. O'Hearn: Resources, Concurrency and Local Reasoning. CONCUR 2004: 49-67 Peter W. O'Hearn: Resources, concurrency, and local reasoning. Theor. Comput. Sci. 375(1-3): 271-307 (2007) Viktor Vafeiadis. Concurrent separation logic and operational semantics. In MFPS 2011. ENTCS 276, pp. 335-351. Elsevier (Sep. 2011)