/ PSWLAB Concurrent Bug Patterns and How to Test Them by Eitan Farchi, Yarden Nir, Shmuel Ur published in the proceedings of IPDPS’03 (PADTAD2003)

Slides:



Advertisements
Similar presentations
Synchronization. How to synchronize processes? – Need to protect access to shared data to avoid problems like race conditions – Typical example: Updating.
Advertisements

Concurrent Programming Abstraction & Java Threads
Background Concurrent access to shared data can lead to inconsistencies Maintaining data consistency among cooperating processes is critical What is wrong.
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
1 CSC321 §2 Concurrent Programming Abstraction & Java Threads Section 2 Concurrent Programming Abstraction & Java Threads.
/ PSWLAB Atomizer: A Dynamic Atomicity Checker For Multithreaded Programs By Cormac Flanagan, Stephen N. Freund 24 th April, 2008 Hong,Shin.
Threading Part 2 CS221 – 4/22/09. Where We Left Off Simple Threads Program: – Start a worker thread from the Main thread – Worker thread prints messages.
“THREADS CANNOT BE IMPLEMENTED AS A LIBRARY” HANS-J. BOEHM, HP LABS Presented by Seema Saijpaul CS-510.
Programming Language Semantics Java Threads and Locks Informal Introduction The Java Specification Language Chapter 17.
Synchronization in Java Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Synchronization in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Sharing Objects – Ch. 3 Visibility What is the source of the issue? Volatile Dekker’s algorithm Publication and Escape Thread Confinement Immutability.
/ PSWLAB Eraser: A Dynamic Data Race Detector for Multithreaded Programs By Stefan Savage et al 5 th Mar 2008 presented by Hong,Shin Eraser:
Learning From Mistakes—A Comprehensive Study on Real World Concurrency Bug Characteristics Shan Lu, Soyeon Park, Eunsoo Seo and Yuanyuan Zhou Appeared.
Exceptions and Mistakes CSE788 John Eisenlohr. Big Question How can we improve the quality of concurrent software?
CS510 Concurrent Systems Introduction to Concurrency.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
Concurrency, Mutual Exclusion and Synchronization.
Threading and Concurrency Issues ● Creating Threads ● In Java ● Subclassing Thread ● Implementing Runnable ● Synchronization ● Immutable ● Synchronized.
1 Concurrent Languages – Part 1 COMP 640 Programming Languages.
 2004 Deitel & Associates, Inc. All rights reserved. 1 Chapter 4 – Thread Concepts Outline 4.1 Introduction 4.2Definition of Thread 4.3Motivation for.
Games Development 2 Concurrent Programming CO3301 Week 9.
Optimistic Design 1. Guarded Methods Do something based on the fact that one or more objects have particular states  Make a set of purchases assuming.
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.
Producer-Consumer Problem The problem describes two processes, the producer and the consumer, who share a common, fixed-size buffer used as a queue.bufferqueue.
Synchronized and Monitors. synchronized is a Java keyword to denote a block of code which must be executed atomically (uninterrupted). It can be applied.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
Threaded Programming in Python Adapted from Fundamentals of Python: From First Programs Through Data Structures CPE 401 / 601 Computer Network Systems.
System calls for Process management
Lecture 8 Page 1 CS 111 Online Other Important Synchronization Primitives Semaphores Mutexes Monitors.
Memory Consistency Models. Outline Review of multi-threaded program execution on uniprocessor Need for memory consistency models Sequential consistency.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
Consider the program fragment below left. Assume that the program containing this fragment executes t1() and t2() on separate threads running on separate.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
ICFEM 2002, Shanghai Reasoning about Hardware and Software Memory Models Abhik Roychoudhury School of Computing National University of Singapore.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
CS533 – Spring Jeanie M. Schwenk Experiences and Processes and Monitors with Mesa What is Mesa? “Mesa is a strongly typed, block structured programming.
Fall 2008Programming Development Techniques 1 Topic 20 Concurrency Section 3.4.
Comunication&Synchronization threads 1 Programación Concurrente Benemérita Universidad Autónoma de Puebla Facultad de Ciencias de la Computación Comunicación.
Optimistic Design CDP 1. Guarded Methods Do something based on the fact that one or more objects have particular states Make a set of purchases assuming.
/ PSWLAB Thread Modular Model Checking by Cormac Flanagan and Shaz Qadeer (published in Spin’03) Hong,Shin Thread Modular Model.
System calls for Process management Process creation, termination, waiting.
CS510 Concurrent Systems Jonathan Walpole. Introduction to Concurrency.
18 September 2008CIS 340 # 1 Last Covered (almost)(almost) Variety of middleware mechanisms Gain? Enable n-tier architectures while not necessarily using.
Agenda  Quick Review  Finish Introduction  Java Threads.
Concurrency in Java MD. ANISUR RAHMAN. slide 2 Concurrency  Multiprogramming  Single processor runs several programs at the same time  Each program.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Concurrent Programming in Java Based on Notes by J. Johns (based on Java in a Nutshell, Learning Java) Also Java Tutorial, Concurrent Programming in Java.
Lecture 5 Page 1 CS 111 Summer 2013 Bounded Buffers A higher level abstraction than shared domains or simple messages But not quite as high level as RPC.
Tutorial 2: Homework 1 and Project 1
Chapter 4 – Thread Concepts
Healing Data Races On-The-Fly
Multithreading / Concurrency
Threaded Programming in Python
Background on the need for Synchronization
Chapter 4 – Thread Concepts
Multithreading Chapter 23.
Producer-Consumer Problem
Lecture 2 Part 2 Process Synchronization
Dr. Mustafa Cem Kasapbaşı
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization
CS333 Intro to Operating Systems
Foundations and Definitions
Programming with Shared Memory Specifying parallelism
“The Little Book on Semaphores” Allen B. Downey
CSE 332: Concurrency and Locks
CSE 542: Operating Systems
Presentation transcript:

/ PSWLAB Concurrent Bug Patterns and How to Test Them by Eitan Farchi, Yarden Nir, Shmuel Ur published in the proceedings of IPDPS’03 (PADTAD2003) presented by Hong,Shin Concurrent Bug Patterns and How to Test Them

/ PSWLAB Contents Introduction Concurrent Bug Pattern Deducing Concurrent Bug Patterns from Design Patterns Heuristics for Finding Concurrent Bug Concurrent Bug Patterns and How to Test Them2

/ PSWLAB Introduction (1/2) A bug taxonomy for sequential programs was used to motivate test techniques.  Make a bug taxonomy for concurrent programs and develop test techniques based on the bug taxonomy. Goal –describes and categorizes a detailed taxonomy of concurrent bugs in Java By cause By related design pattern –use the taxonomy to create new heuristics for testing Concurrent Bug Patterns and How to Test Them3

/ PSWLAB Introduction (2/2) For a concurrent program P, –I(P) : the set of interleaving runs that can occur in P –C(P) : the set of interleaving runs under which the program is correct. –A concurrent bug pattern can be viewed as defining runs in I(P) – C(P). A concurrent event is an accessing to an interesting shared variable or synchronization event such as lock acquiring and releasing Concurrent Bug Patterns and How to Test Them4

/ PSWLAB Concurrent Bug Patterns (1/9) The following high level categories of concurrent bug patterns can be identified (by cause). –Code assumed to be protected bug patterns A run in I(P) – C(P) is created when a code segment is mistakenly assumed to be undisturbed by other threads. –Interleaving assumed never occur bug patterns A run in I(P) – C(P) is created as a result of the mistaken assumption that a certain execution order of concurrent events is impossible. –Blocking or dead thread bug patterns A run in I(P) – C(P) is created when a code segment is mistakenly assumed to be non-blocking Concurrent Bug Patterns and How to Test Them5

/ PSWLAB Concurrent Bug Patterns (2/9) Code assumed to be protected bug patterns –A code segment is protected (or undisturbed) for a concurrent program P, if for any run in I(P), no other thread executes a concurrent event while the code segment is executed. –A bug pattern occurs when a code segment is assumed to be protected but is actually not. - Nonatomic operations assumed to be atomic - Two-stage access bug pattern - Wrong lock or no lock - Double checked locking Concurrent Bug Patterns and How to Test Them6

/ PSWLAB Concurrent Bug Patterns (3/9) Nonatomic operations assumed to be atomic An operation that looks like one operation in the source code level of the programming language but actually consists of several unprotected operations at the lower abstraction levels. For example, in Java version 1.3.1, x++ operation for a class instance field is translated to three bytecode instructions: 1) move the current value of x from the heap to the thread’s local area copy of x 2) increment the thread’s local area value by one 3) update the heap value of x And these three instructions are not protected Concurrent Bug Patterns and How to Test Them7

/ PSWLAB Concurrent Bug Patterns (4/9) Two-stage access bug pattern For a sequence of operations that should be protected, the programmer wrongly assumes that separately protecting each operation is enough. For example, key = getKey(id) ; value = getValue(key) ; Even though getKey() is protected and getValue() is protected, the program is erroneous if these two operations are not protected Concurrent Bug Patterns and How to Test Them8

/ PSWLAB Concurrent Bug Patterns (5/9) Wrong lock or no lock A shared resource is protected by a lock but there exists a thread which does not obtain the same lock instance when accessing the resource. For example, First thread executes synchronized(o) { x++ ; } while the second thread executes x++ ; The possible final value for x can be Concurrent Bug Patterns and How to Test Them9

/ PSWLAB Concurrent Bug Patterns (6/9) Double-checked locking When an object is initialized, the thread local copy of the object’s field is initialized but not all object fields are necessarily written to the heap. This might cause the object to be partially initialized while its reference is not null Concurrent Bug Patterns and How to Test Them10 class Foo { private Helper helper = null; public Helper getHelper() { if (helper == null) synchronized(this) { if (helper == null) helper = new Helper(); /* while Helper() is executing, } helper may not be null */ return helper; }

/ PSWLAB Concurrent Bug Patterns (7/9) Interleaving assumed never to occur –The programmer assumes that a certain execution never occurs because of some assumptions on the underlying hardware, or some order of execution forced by explicit delays (e.g. sleep(), yield() ) –But such executions are possible actually. –Patterns: - The sleep() bug pattern - Losing a notify bug pattern Concurrent Bug Patterns and How to Test Them11

/ PSWLAB Concurrent Bug Patterns (8/9) The sleep() bug pattern The programmer adds sleep() operation in a parent thread right after child thread creation to wait until the child is initialized. However, there is no guarantee that the child thread finishes the initializing before the parent thread wake up. The correct solution is that the parent thread explicitly wait for the child thread. Losing a notify bug pattern If a notify() is executed before its corresponding wait(), the notify() has no effect, and the code executing wait() might not be awakened. One way of avoiding this bug pattern is to repeatedly execute the notify() operation until a condition stating that the notify() was received occurs Concurrent Bug Patterns and How to Test Them12

/ PSWLAB Concurrent Bug Patterns (9/9) Blocking or dead thread bug pattern –Some runs in I(P) – C(P) contain a blocking operation that blocks indefinitely. –Patterns: - A blocking critical section bug pattern A thread is assumed to eventually return control but it never does. - The orphaned thread bug pattern In a master-slaves system, if the master thread terminates abnormally, the remaining threads may continue to run, awaiting more input from the master and causing the system to hang Concurrent Bug Patterns and How to Test Them13

/ PSWLAB Deducing Concurrent Bug Patterns from Design Patterns(1/3) Concurrent design patterns can also be used to deduce typical concurrent bug patterns.  A bug pattern might be related to a design pattern. –Confinement and subclassing –The token design pattern –The fork/join design pattern Concurrent Bug Patterns and How to Test Them14

/ PSWLAB Deducing Concurrent Bug Patterns from Design Patterns(2/3) Confinement and subclassing A confined mode is a mode where all methods are protected by a lock and leak of references to class instances other than the confined class is prevented. A subclass is incorrectly implemented that it can access the bare class both in confined mode and in nonconfined mode. This bug pattern is also belong to “wrong lock or no lock” bug pattern Concurrent Bug Patterns and How to Test Them15

/ PSWLAB Deducing Concurrent Bug Patterns from Design Patterns(3/3) The token design pattern Only one thread can hold a token at any given time. If this property is destroyed, the program may occur an error. For example, after a resource transfer of the form x.r = y.s, if the resource is a token, then it occurs an error because y still points to the same resource s. A proper transfer should look like atomic { x.r=y.s ; y=null ; } This bug is associated with “code assumed to be protected” Concurrent Bug Patterns and How to Test Them16

/ PSWLAB Heuristics for Finding Concurrent Bug (1/2) Timing heuristics are used to increase the probability that known kinds of concurrent bugs will occur. –At run time, the runtime controller is given control before and after a concurrent event is executed. –The controller can use Java primitives such as sleep() and yield() to change the order of concurrent event execution. –Use ConTest tool for instrumentation and testing Concurrent Bug Patterns and How to Test Them17

/ PSWLAB Heuristics for Finding Concurrent Bug (2/2) Example- Lost notify bug pattern - Below code is inserted in front of o.wait(). otherAdvancing = true ; while (otherAdvancing) { otherAdvancing = false ; sleep(duration) ; } - Below code is inserted in front of o.notify(). otherAdvancing = true ; - This timing heuristic increases the chance that the lost notify bug manifest. Example – The sleep() bug pattern - At run time, the sleep() duration is randomly changed to manifest the bug Concurrent Bug Patterns and How to Test Them18

/ PSWLAB Conclusion This paper categorizes a taxonomy of concurrent bug patterns. And shows testing techniques can be enhanced and developed using the bug taxonomy Concurrent Bug Patterns and How to Test Them19

/ PSWLAB Further work Antipatterns Assisting the Code Review Process Using Simple Pattern Recognition by Eitan Farchi, Bradley R. Harrington, HVC2005 Techniques for specifying bug patterns by Daniel J. Quinlan et al, PADTAD Concurrent Bug Patterns and How to Test Them20