Joint work with Yong Li, Xinyu Feng, Zhong Shao and Yu Zhang

Slides:



Advertisements
Similar presentations
1 Lecture 5 Towards a Verifying Compiler: Multithreading Wolfram Schulte Microsoft Research Formal Methods 2006 Race Conditions, Locks, Deadlocks, Invariants,
Advertisements

Dataflow Analysis for Datarace-Free Programs (ESOP 11) Arnab De Joint work with Deepak DSouza and Rupesh Nasre Indian Institute of Science, Bangalore.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Challenges in increasing tool support for programming K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 23 Sep 2004 ICTAC Guiyang, Guizhou, PRC joint.
Copyright W. Howden1 Programming by Contract CSE 111 6/4/2014.
Hongjin Liang and Xinyu Feng
TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A A A AAA A A A AA A Proving that non-blocking algorithms don't block.
Semantics Static semantics Dynamic semantics attribute grammars
An Case for an Interleaving Constrained Shared-Memory Multi-Processor Jie Yu and Satish Narayanasamy University of Michigan.
Reduction, abstraction, and atomicity: How much can we prove about concurrent programs using them? Serdar Tasiran Koç University Istanbul, Turkey Tayfun.
Verification of Multithreaded Object- Oriented Programs with Invariants Bart Jacobs, K. Rustan M. Leino, Wolfram Schulte.
A Rely-Guarantee-Based Simulation for Verifying Concurrent Program Transformations Hongjin Liang, Xinyu Feng & Ming Fu Univ. of Science and Technology.
Reasoning About Code; Hoare Logic, continued
A simple sequential reasoning approach for sound modular verification of mainstream multithreaded programs Wolfram Schulte & Bart Jacobs Microsoft Research.
Maged M. Michael, “Hazard Pointers: Safe Memory Reclamation for Lock- Free Objects” Presentation Robert T. Bauer.
Scalable Synchronous Queues By William N. Scherer III, Doug Lea, and Michael L. Scott Presented by Ran Isenberg.
Certifying Low-Level Programs with Hardware Interrupts and Preemptive Threads Xinyu Feng Toyota Technological Institute at Chicago Joint work with Zhong.
© 2004 Goodrich, Tamassia Linked Lists1. © 2004 Goodrich, Tamassia Linked Lists2 Singly Linked List (§ 4.4.1) A singly linked list is a concrete data.
An Open Framework for Foundational Proof-Carrying Code Xinyu Feng Yale University Joint work with Zhaozhong Ni (Yale, now at MSR), Zhong Shao (Yale) and.
On the Relationship Between Concurrent Separation Logic and Assume-Guarantee Reasoning Xinyu Feng Yale University Joint work with Rodrigo Ferreira and.
Michael Ernst, page 1 Improving Test Suites via Operational Abstraction Michael Ernst MIT Lab for Computer Science Joint.
1 Sharing Objects – Ch. 3 Visibility What is the source of the issue? Volatile Dekker’s algorithm Publication and Escape Thread Confinement Immutability.
1 A Modular Checker for Multithreaded Programs Cormac Flanagan HP Systems Research Center Joint work with Shaz Qadeer Sanjit A. Seshia.
Thread-Modular Verification Shaz Qadeer Joint work with Cormac Flanagan Stephen Freund Shaz Qadeer Joint work with Cormac Flanagan Stephen Freund.
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.
An example demonstrating the ABA problem Xinyu Feng University of Science and Technology of China.
Compositional Verification of Termination-Preserving Refinement of Concurrent Programs Hongjin Liang Univ. of Science and Technology of China (USTC) Joint.
Verifying Concurrent Objects under Fair Scheduling Hongjin Liang University of Science and Technology of China (USTC) Joint work with Xinyu Feng.
Aquinas Hobor and Cristian Gherghina (National University of Singapore) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:
Concurrency Verification. Why concurrency verification Concurrent programs show in many systems –Multi-task support in OS kernels –Handling interrupts.
Characterizing Progress Properties of Concurrent Objects via Contextual Refinements Hongjin Liang Univ. of Science and Technology of China (USTC) Joint.
COMP 111 Threads and concurrency Sept 28, Tufts University Computer Science2 Who is this guy? I am not Prof. Couch Obvious? Sam Guyer New assistant.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
Reasoning about programs March CSE 403, Winter 2011, Brun.
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen.
Automated and Modular Refinement Reasoning for Concurrent Programs Shaz Qadeer.
Program Logic for Concurrency Refinement Verification Xinyu Feng University of Science and Technology of China Joint work with Hongjin Liang (USTC) and.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
/ PSWLAB Thread Modular Model Checking by Cormac Flanagan and Shaz Qadeer (published in Spin’03) Hong,Shin Thread Modular Model.
Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects MAGED M. MICHAEL PRESENTED BY NURIT MOSCOVICI ADVANCED TOPICS IN CONCURRENT PROGRAMMING,
Program Analysis and Verification
Simplifying Linearizability Proofs Using Reduction and Abstraction Serdar Tasiran Koc University, Istanbul, Turkey Tayfun Elmas, Ali Sezgin, Omer Subasi.
A Calculus of Atomic Actions Serdar Tasiran Koc University, Istanbul, Turkey Tayfun ElmasShaz Qadeer Koc University Microsoft Research.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
Spring 2017 Program Analysis and Verification
STACKS & QUEUES for CLASS XII ( C++).
Concurrency 2 CS 2110 – Spring 2016.
An Operational Approach to Relaxed Memory Models
Low-Level Program Verification
Reasoning About Code.
Reasoning about code CSE 331 University of Washington.
Graph-Based Operational Semantics
Concepts of programming languages
CS510 Concurrent Systems Jonathan Walpole.
Verification of Concurrent Programs
Concurrency Verification
Hongjin Liang, Xinyu Feng & Ming Fu
CS510 Concurrent Systems Jonathan Walpole.
Lecture 5 Floyd-Hoare Style Verification
Lecture 6: Transactions
CS510 - Portland State University
Over-Approximating Boolean Programs with Unbounded Thread Creation
Separation Logic and Concurrency Verification
Multicore programming
Multicore programming
Multicore programming
CS510 Advanced Topics in Concurrency
CS510 Concurrent Systems Jonathan Walpole.
Presentation transcript:

Joint work with Yong Li, Xinyu Feng, Zhong Shao and Yu Zhang Reasoning about Optimistic Concurrency Using a Program Logic for History Ming Fu USTC & Yale Joint work with Yong Li, Xinyu Feng, Zhong Shao and Yu Zhang

What is Optimistic Concurrency? Increments the shared variable x atomically: Optimistic Concurrency Ensuring data consistency by conflict detection More efficient than coarse-grained lock-based synchronization Complex, error-prone and hard to verify Pessimistic Optimistic lock x; x++; unlock x; int t; do { t = x; }while (!CAS(&x, t, t+1))

An Optimistic Non-blocking Stack Top n Next n Next … pop( ){ local done, next, t; done = false; while (!done) { t = Top; if (t==null) return null; next = t.Next; done = CAS(&Top, t, next); } return t; push(x){ local done, t; done = false; while(!done) { x.Next = t; done = CAS(&Top, t, x); return true; Bug#1: t might be a dangling pointer Bug#2: ABA problem leads to corrupted stacks

ABA Problem T1 and T2 do pops and pushes, interleaved as follows: T2: a = pop(); c = pop(); push(a); Top B C next (removed) Top Top T1: pop() { read t read next interrupt resume CAS succeeds stack corrupted t t A A next C B B next C (removed) Timeline

Fix Bugs with Hazard Pointers [Michael04] pop( ){ local done, next, t, t1; done = false; while (!done) { t = Top; if (t==null) return null; HP[tid] = t; t1 := Top; if (t == t1){ next = t.Next; done = CAS(&Top, t, next); } retireNode(t); HP[tid] = null; return t; push(x) local done, t; done = false; while(!done) { x.Next := t; done = CAS(&Top, t, x); return true; retireNode(t): local i, t; i := 1; while(i<=th_num){ if (i != tid){ t’ := HP[i]; if (t’!= t) i:= i+1; }else i:= i+1; }

pop( ){ local done, next, t, t1; done = false; while (!done) { t = Top; if (t==null) return null; HP[tid] = t; t1 := Top; if (t == t1){ next = t.Next; done = CAS(&Top, t, next); } retireNode(t); HP[tid] = null; return t; nodes on stack removed nodes pointed by hazard pointers reclaimable nodes HP 1 2 Top removed by 3 hazard to 3 3 tid A A A hazard to 5 4 5 C hazard to 7 6 B 7

Verifying Stacks with Hazard Pointers using CSL [Matthew POPL07] History variables HP’[tid] and auxiliary codes are used for representing some temporal properties pop(){ 03 while (!done){ . . . 06 <HP[tid] = t; HP’[tid] = Req >; 07 <if (Top != t) continue; else HP’[tid] = Tail(t.Next) >; 08 <next = t.Next; if (HP’[tid] != Tail(next)) HP’[tid] = Left>; 09 <done = CAS(&Top, t, next)>; 10 } 11 } } An indirect approach to specifying historical events

A Program Logic for History (HLRG) Introduces past tense temporal operators into Rely-Guarantee Reasoning! HLRG gives us the following benefit: No history variables

Extensions in HLRG Program Traces Trace-based Operational Semantics Trace assertions p, q, R, G::= P | Id | p q | …

p q p q q q q Time p holds over the historical trace q holds ever since

p = (p true) \/ p Time s0 s1 s2 s3 s4 s5 s6 p p was once true in the history, including the current trace.

... p = ( p) p p p Time p holds at every step in the history s0 s1 s2

Rely-Guarantee Reasoning [Jones'83] Basic judgment: R,G┝ {p} C {q} R: invariant of environment’s transitions G: invariant of the thread’s transitions p: precondition q: postcondition R/G cannot express directly the temporal properties about the subtle interaction between threads !

Frame Time & Invariants Rules Basic judgment: R,G┝ {p} C {q} R/G, p, q are trace assertions (R, G)┝ {p r} C {q r} (FrameT) (R, G)┝ {p} C {q} Knowledge about history can be added when necessary! (R, G)┝ {p} C {q I’} (Inv) (R, G)┝ {p I} C {q} (R G) (I I’) Derived invariants I and I’ can be used for free!

point to A and CAS succeeds Verification of pop nodes on stack removed nodes pointed by hazard pointers reclaimable nodes Shared Resources Shared = Top * Stack * RN*HP HP 1 Temporal property for each node In RN 2 removed by 3 remove(A, tid) : 3 A A HP[tid] & Top point to A and CAS succeeds Top Ishazard to 5 4 HP[tid] points to A 5 C Ishazard to 7 6 Removed by a thread t in the history and pointed by the hazard pointer of thread tid ever since B 7

For all other tid’ , Ishazard(A, tid’) Verification of pop nodes on stack removed nodes pointed by hazard pointers reclaimable nodes Shared Resources Ishazard(A, tid) : HP HP[tid] & Top point to A (HP[tid] points to A) and not (tid updates Top) 1 2 removed by 3 3 retireNode(A) A A Top Ishazard to 5 4 hazardfree(A, tid) : 5 C Ishazard to 7 For all other tid’ , Ishazard(A, tid’) 6 remove(A, tid) B 7

Applying Inv Rule in the proof pop( ){ … if (t == t1){ {Ishazard(t,tid)} {Ishazard(t,tid) * t |-> _, _} next = t.Next; done = CAS(&Top, t, next); } retireNode(t); HP[tid] = null; return t; (R \/ G) Apply Inv rule with Invariants INV1 for avoiding Bug#1: for all t, tid, ishazard(t, tid) /\ t ≠ null => t Є Stack \/ t Є RN see CONCUR’10 paper for details!

Conclusion A Program Logic for History (HLRG) R-G reasoning + past tense temporal assertions Specifying historical events directly without using history variables modular verification (frame rules over space and time) Verifying the correctness of Michael’s non-blocking stacks

Thank you! Questions?