Model Checking of a lock-free stack

Slides:



Advertisements
Similar presentations
CS492B Analysis of Concurrent Programs Lock Basics Jaehyuk Huh Computer Science, KAIST.
Advertisements

Mutual Exclusion By Shiran Mizrahi. Critical Section class Counter { private int value = 1; //counter starts at one public Counter(int c) { //constructor.
1 Operating Systems, 122 Practical Session 5, Synchronization 1.
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.
Introduction to Lock-free Data-structures and algorithms Micah J Best May 14/09.
1 Function Calls Professor Jennifer Rexford COS 217 Reading: Chapter 4 of “Programming From the Ground Up” (available online from the course Web site)
CS510 Concurrent Systems Class 2 A Lock-Free Multiprocessor OS Kernel.
A. Frank - P. Weisberg Operating Systems Introduction to Cooperating Processes.
Exceptions. Many problems in code are handled when the code is compiled, but not all Some are impossible to catch before the program is run  Must run.
Introduction to Embedded Systems
Preventing and Correcting Errors
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
Java Software Solutions Lewis and Loftus Chapter 14 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Advanced Flow of Control --
Multithreading : synchronization. Avanced Programming 2004, Based on LYS Stefanus’s slides slide 4.2 Solving the Race Condition Problem A thread must.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
Nachos Project 4 Lecturer: Hao-Hua Chu TA: Chun-Po Wang (Artoo) Date: 2008/10/25.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
1 Lock-Free concurrent algorithm for Linked lists: Verification CSE-COSC6490A : Concurrent Object-Oriented Languages York University - W09 Speaker: Alexandre.
Linux Processes Travis Willey Jeff Mihalik. What is a process? A process is a program in execution A process includes: –program counter –stack –data section.
IT 325 Operating systems Chapter6.  Threads can greatly simplify writing elegant and efficient programs.  However, there are problems when multiple.
1 Condition Variables CS 241 Prof. Brighten Godfrey March 16, 2012 University of Illinois.
Process Management Azzam Mourad COEN 346.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Scalable lock-free Stack Algorithm Wael Yehia York University February 8, 2010.
Thread Basic Thread operations include thread creation, termination, synchronization, data management Threads in the same process share:  Process address.
Distributed Algorithms (22903) Lecturer: Danny Hendler Lock-free stack algorithms.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Threads Some of these slides were originally made by Dr. Roger deBry. They include text, figures, and information from this class’s textbook, Operating.
Checking nonblocking concurrent queue program
Topic 3 (Textbook - Chapter 3) Processes
Chapter 3: Process Concept
Multiple Writers and Races
Stacks and Queues.
Queues Queues Queues.
Chapter 3: Processes.
CS 153: Concepts of Compiler Design November 28 Class Meeting
Distributed Algorithms (22903)
Distributed Algorithms (22903)
CS510 Concurrent Systems Jonathan Walpole.
Distributed Algorithms (22903)
System Structure and Process Model
Chapter 3: Processes.
System Structure and Process Model
Chapter 9 :: Subroutines and Control Abstraction
Distributed Algorithms (22903)
System Structure B. Ramamurthy.
EECE.4810/EECE.5730 Operating Systems
CS510 Concurrent Systems Jonathan Walpole.
Chap. 8 :: Subroutines and Control Abstraction
Chap. 8 :: Subroutines and Control Abstraction
COP 4600 Operating Systems Spring 2011
System Structure and Process Model
Processor Fundamentals
CS510 - Portland State University
Chapter 3: Processes.
Multicore programming
COT 5611 Operating Systems Design Principles Spring 2012
Scalable lock-free Stack Algorithm
CS510 Advanced Topics in Concurrency
Java Concurrency.
Java Concurrency.
SWE 619 Last modified Fall 2007 Saket Kaushik, Paul Ammann
Outline Chapter 2 (cont) Chapter 3: Processes Virtual machines
CS510 Concurrent Systems Jonathan Walpole.
Chapter 3: Process Concept
EECE.4810/EECE.5730 Operating Systems
CS444/544 Operating Systems II Scheduler
Presentation transcript:

Model Checking of a lock-free stack Wael Yehia York University March 31, 2010

Main Components of the Stack The stack was simply a top pointer Each thread has a ThreadInfo object that uniquely identifies the thread Two arrays, for collision and (lock-free) synchronization purposes AtomicIntegerArray collision AtomicReferenceArray<ThreadInfo<T>> location threadInfo<T> final int id OP op cell<T> cell

JPF Testing We ran JPF on our test cases from assignment 2, lowering the # of threads and operations. We found: no deadlocks 1 Data Race (not fixed, so maybe more) 3 Uncaught Exceptions (All fixed)

Data Races Found Tested on different number of threads and number of operations per thread For 2 threads, no Data Races were found # of ops: 2, 3, 4, 5 were tested For 3 threads, a Data Race was found. Could not be fixed. The race was also related to the same problem that causes the NullPointerException discussed later.

Uncaught Exceptions found One NullPointerException Two AssertionError() Exceptions The null pointer and one of the assertion errors seemed to be related. Occur due to the same scenario that causes the Data Race When the problem was fixed, so was the second assertion error 

The Untested Scenario The null pointer and the data race problems rise in the following situation (which is not accounted for in the paper): Let p stand for Thread p, q for Thread q, and qInfo for q’s ThreadInfo p.pop() q.push() Collide with q - q sees someone has collide with it - q exits normally - q starts another operation either operations alter qInfo.cell - p read qInfo.cell

The Untested Scenario In general, the scenario is as follows: Two threads collide ( p.pop() and q.push() ) The pushing thread finishes first and exits. Then it executes another stack operation before the popping thread reads any data from it. The popping thread wakes up and starts reading the data from q’s ThreadInfo

Solution It is obvious that the problem occurs when one thread (popping p) is slow in reading the data from the second thread (pushing q). The fast thread cannot wait for the slow thread, so it has to store it’s data somewhere. Quick Reminder of the collision process: Two processes cannot be colliding with the same process, so their collision relation looks like this: …. q p r …. State of the location Array (that hold threadinfo’s) during a collision: 3 Threads: q pushing, p popping, r popping p.id = 0, q.id = 1, r.id = 2 Array before collision: Array after collision: collide with collide with collide with Threadinfo Threadinfo Threadinfo of p of q of r Threadinfo null Don’t care of q

Solution (Cont’d) Solution part (a) (when q starts the collision): instead of saving it’s ThreadInfo in popping thread’s slot, create and store a new dummy ThreadInfo holding the data Solution part (b) (when p starts the collision): Before attempting the collision, save the q’s data locally When collision succeeds, use it, otherwise discard it

Conclusion JPF helped us find and understand the problem more clearly. The exception caught by jpf took seconds or minutes at most. While during our testing, they appeared once every millions of operations executed by many threads concurrently. The described scenario will fail the algorithm presented in the paper. The Data race has still to be fixed