Concurrency Analysis of Asynchronous APIs

Similar documents
Race Detection for Nested Event Concurrent Software

JS Event Loop, Promises, Async Await etc. Slava Kim

Swift 5, ABI Stability and

Chapter 4: Threads. Operating System Concepts. Silberschatz, Galvin and Gagne

Software-Controlled Multithreading Using Informing Memory Operations

Questions from last time

The Various Faces of the.net Task Parallel Library

Chapter 4: Threads. Chapter 4: Threads. Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues

Concurrency, Mutual Exclusion and Synchronization C H A P T E R 5

Process Description and Control

Asynchronous Programming Demystified

Active Testing for Concurrent Programs

Intel Threading Tools

Active Testing for Concurrent Programs

EventRacer: Finding Concurrency Errors in Event-Driven Applications. Pavol Bielik

Chapter 4: Threads. Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads

SOFTWARE MAINTENANCE AND EVOLUTION --- REFACTORING FOR ASYNC --- CS563 WEEK 3 - THU

An Async Primer. By Bill Wagner August Introduction

Chapter 4: Threads. Operating System Concepts 9 th Edition

CS 450 Operating System Week 4 Lecture Notes

Chapter 4: Multithreaded Programming

Multithreading and Interactive Programs

Scala Actors. Scalable Multithreading on the JVM. Philipp Haller. Ph.D. candidate Programming Methods Lab EPFL, Lausanne, Switzerland

Software Architecture and Engineering: Part II

POINT OF FAILURES TOPICS .NET. msdn

Chapter 4: Threads. Operating System Concepts 9 th Edition

Produced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar

Asynchronous Functions in C#

Distributed systems. Programming with threads

Chapter 4: Threads. Operating System Concepts 9 th Edit9on

Threads Questions Important Questions

Definition Multithreading Models Threading Issues Pthreads (Unix)

Chapter 4: Threads. Chapter 4: Threads

Outline. Threads. Single and Multithreaded Processes. Benefits of Threads. Eike Ritter 1. Modified: October 16, 2012

Efficient Data Race Detection for Unified Parallel C

Chapter 4: Multithreaded

Recap. Contents. Reenterancy of synchronized. Explicit Locks: ReentrantLock. Reenterancy of synchronise (ctd) Advanced Thread programming.

Thinking parallel. Decomposition. Thinking parallel. COMP528 Ways of exploiting parallelism, or thinking parallel

Causal-consistent Reversible Debugging

Concurrent and Distributed Systems Introduction

Chapter 4: Multi-Threaded Programming

3.1 Introduction. Computers perform operations concurrently

Parallel Code Smells: A Top 10 List

C# Threading. Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh

POSIX Threads: a first step toward parallel programming. George Bosilca

OPERATING SYSTEM. Chapter 4: Threads

GDB-UPC for GCC-UPC SMP runtime. GDB-UPC features. GDB features. Multiprocessing support in GDB. GDB UPC for SMP runtime Intrepid Technology, Inc.

Process Characteristics

Processes and Threads

Executive Summary. It is important for a Java Programmer to understand the power and limitations of concurrent programming in Java using threads.

Lecture 15: Data-Driven Tasks, Point-to-Point Synchronization with Phasers

Problems with Concurrency

Operating Systems (2INC0) 2018/19. Introduction (01) Dr. Tanir Ozcelebi. Courtesy of Prof. Dr. Johan Lukkien. System Architecture and Networking Group

Overview. Administrative. * HW 2 Grades. * HW 3 Due. Topics: * What are Threads? * Motivating Example : Async. Read() * POSIX Threads

Multithreading and Interactive Programs

Threads Implementation. Jo, Heeseung

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

IT 540 Operating Systems ECE519 Advanced Operating Systems

IT 540 Operating Systems ECE519 Advanced Operating Systems

COREMU: a Portable and Scalable Parallel Full-system Emulator

Writing Parallel Programs COMP360

Chapter 4: Threads. Chapter 4: Threads

ClearSpeed Visual Profiler

Reactive Web Programming

MCSA Universal Windows Platform. A Success Guide to Prepare- Programming in C# edusum.com

Deviations are things that modify a thread s normal flow of control. Unix has long had signals, and these must be dealt with in multithreaded

Asynchronous Programming with Async and Await 1 Await Operator 12 Async 15 Accessing the Web by Using Async and Await 18 Extend the Async Walkthrough

Chapter 4: Multithreaded Programming

CPSC 213. Introduction to Computer Systems. I/O Devices, Interrupts and DMA. Unit 2a Oct 27, 29, 31. Winter Session 2014, Term 1

Chapter 4: Multithreaded Programming. Operating System Concepts 8 th Edition,

INF 212 ANALYSIS OF PROG. LANGS CONCURRENCY. Instructors: Crista Lopes Copyright Instructors.

AJAX: Asynchronous Event Handling Sunnie Chung

Dealing with Issues for Interprocess Communication

Computation Abstractions. Processes vs. Threads. So, What Is a Thread? CMSC 433 Programming Language Technologies and Paradigms Spring 2007

CalFuzzer: An Extensible Active Testing Framework for Concurrent Programs Pallavi Joshi 1, Mayur Naik 2, Chang-Seo Park 1, and Koushik Sen 1

DNParallel - Version: 3. TPL Dataflow

Written Presentation: JoCaml, a Language for Concurrent Distributed and Mobile Programming

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Concurrency, Thread. Dongkun Shin, SKKU

Concurrency in Software Designs: How to Avoid Nasty Surprises?

HPX. High Performance ParalleX CCT Tech Talk Series. Hartmut Kaiser

Java Threads. COMP 585 Noteset #2 1

CSCE Introduction to Computer Systems Spring 2019

Benefits of Concurrency in Java & Android: Program Structure

Exception-Less System Calls for Event-Driven Servers

Last class: Today: Thread Background. Thread Systems

CSP IN JAVASCRIPT.

Capriccio: Scalable Threads for Internet Services

Networking, Java threads and synchronization. PRIS lecture 4 Fredrik Kilander

Concurrency Control. Synchronization. Brief Preview of Scheduling. Motivating Example. Motivating Example (Cont d) Interleaved Schedules

Operating System. Chapter 4. Threads. Lynn Choi School of Electrical Engineering

Today: Distributed Middleware. Middleware

Introduction to Coroutines. Roman Elizarov elizarov at JetBrains

Speculative Synchronization: Applying Thread Level Speculation to Parallel Applications. University of Illinois

LINUX INTERNALS & NETWORKING Weekend Workshop

A Deterministic Concurrent Language for Embedded Systems

Introduction to parallel Computing

Cooperari A tool for cooperative testing of multithreaded Java programs

PROCESSES AND THREADS THREADING MODELS. CS124 Operating Systems Winter , Lecture 8

Administrivia. Nachos guide and Lab #1 are on the web.

Transcription:

Concurrency Analysis of Asynchronous APIs Anirudh Santhiar and Aditya Kanade April 2, 2016 Computer Science and Automation, IISc

Introduction Asynchronous Programming Model1 A way to organize programs to avoid blocking. In a nutshell waiting in line for your idly vs registering your order, doing other things, having store call you when ready. We analyze the concurrency behaviours of Event driven asynchronous libraries with programmatic event loops to detect races (joint work with S. Kaleeswaran) C# asynchronous programs to find deadlocks 1 Images courtesy tripadvisor.in and commons.wikimedia.com 1

Races involving Programmatic Event Loops An Event Loop is the basic scheduling mechanism for programs that respond to asynchronous events w h i l e (! e x i t ) { e = nextevent ( ) ; p r o c e s s e ; } We consider frameworks where event loops can also be spun programmatically by event handlers Improve responsiveness while waiting for the user or network Prone to interference between handler spinning event loop and handler running inside the loop 2

Bug in KTNef Bug Close the window when an error dialog is shown. Handler QuitHandler in the programmatic event loop The paused handler OpenHandler KTNEFMain... QuitHandler... exec... error loadfile OpenHandler frees this object uses stack bottom Interference between paused handler and handler running inside programmatic event loop The FileOpen event s handler spins a programmatic event loop during the time the error dialog is shown There is a race between FileHandler and QuitHandler that runs in the programmatic event loop Goal Reason about non-determinism introduced by programmatic event loops to detect such races. 3

Our Work Technical Highlights Powerful happens-before framework to detect races beyond the state-of-the art Account for all general scheduling scenarios e.g., recursive and cascaded programmatic event loops Novel sparse happens-before relation enabling faster race detection Contributions Analyzes the programmatic event loop mechanism - widely used in OS APIs, GUI libraries, Browsers Presents happens-before rules to detect race conditions Efficient computation of the happens-before relation: 5 speedup 13 new and harmful race conditions in 9 open-source applications including Okular, Kate and KOrganizer Tools: Instrumentation framework and race detector SparseRacer 4

Deadlocks in Asynchronous Programs Mixing synchronous and asynchronous waiting can lead to deadlocks t.result UI result = Process(contents); IO async Task<String > GetContentsAsync ( Uri uri ) { using ( var client = new HttpClient ()){ // async wait var contents = await client. GetStringAsync ( uri ); result = Process ( contents ); // continuation return result ; } }....... UI event queue public void Button1_Click (...) { var t = GetContentsAsync (...) ; resultbox. Text = t. Result ; // sync wait } t.result is a blocking call that prevents GetContentsAsync from completing In turn, the only way to unblock t.result is for GetContentsAsync to complete The deadlock is observed even though there is no explicit thread creation and locking. 5

Our Work Design a static analysis to detect such deadlocks. Static analysis captures C# semantics for scheduling and async/await - key to determining where suspensions resume, and therefore deadlocking behaviour. Analyzes control flow in the presence of continuations and APIs affecting scheduling behaviour Preliminary results are encouraging - Prototype tool has found previously unknown deadlocks in 7 open source applications 6

Conclusions Programmers increasingly use powerful language features and APIs to structure their programs to take advantage to asynchrony However, this can allow non-determinism at runtime or make reasoning about the flow of control difficult, leading to bugs that are difficult to diagnose or reproduce We have designed static and dynamic techniques to help understand the behaviour of asynchronous programs better, and tools to automatically find some of these bugs that are beyond the state-of-the-art. 7

Extra Slides

Solution Idea Idea Find bugs using non-buggy executions Design trace language to record interesting operations Design happens-before rules to detect possible reorderings of these Determine if there is a re-ordering of event handlers so that conflicting operations such as uses and frees can be reordered to induce bugs Notify programmer about such re-orderings along with debug information 8

Results Application #Ops #Evts #Blks #Interf. Time Handlers in sec Total True Ark 5008 127 148 6 2 2 Cervisia 1726 129 156 14 2 0.3 Kate 83633 194 225 4 1 480 KDF 1089 15 24 1 1 0.2 Kolourpaint 12746 67 75 2 1 12 KOrganizer 58232 273 290 12 2 179 KTnef 1158 258 275 1 1 0.3 KWrite 74105 62 75 4 1 396 Okular 16785 223 273 14 2 15 Total 58 13 Effective! SparseRacer found 13 harmful use after free bugs in 9 popular open source applications. Baseline Avg. for baseline SparseRacer Avg. for SparseRacer Time to compute graph in sec. (log scale) 10 3 10 2 10 1 10 0 10 1 Fast! SparseRacer was 5X faster than the baseline in race detection time. ark cerv kate kdf kpnt korg ktne Applications kwrt okul 9

Asynchronous Operations 2 Synchronous Operations Do not permit the caller to proceed until the operation completes Asynchronous Operations Decouple initiating the operation (short-lived) from waiting for it to complete Concurrency Asynchrony enables concurrent execution Postpone the waiting Overlap the waiting periods of multiple operations Avoid waiting by registering callbacks 2 Slide inspired by Claudio Russo 10