Verifying Concurrent Programs

Size: px
Start display at page:

Download "Verifying Concurrent Programs"

Transcription

1 Verifying Concurrent Programs Daniel Kroening 8 May 1 June 01

2 Outline Shared-Variable Concurrency Predicate Abstraction for Concurrent Programs Boolean Programs with Bounded Replication Boolean Programs with Unbounded Replication D. Kroening: SSFT1 Verifying Concurrent Programs

3 J. Alglave A. Donaldson A. Kaiser T. Wahl Soundness of Data Flow Analyses for Weak Memory Models, APLAS 011 Symmetry-Aware Predicate Abstraction for Shared-Variable Concurrent Programs, CAV 011 Dynamic Cutoff Detection in Parameterized Concurrent Programs, CAV 010 Boom: Taking Boolean Program Model Checking One Step Further, TACAS 010 Symbolic Counter Abstraction for Concurrent Software, CAV 009 D. Kroening: SSFT1 Verifying Concurrent Programs

4 Forms of Concurrency Shared-variable concurrency (Linux pthread library, Win thread API,... ) Share all memory Share OS API (e.g., file descriptors) Multiple processes on the same machine Share file system Can share memory via mmap Programs on different machines Can communicate e.g. via UDP or TCP D. Kroening: SSFT1 Verifying Concurrent Programs

5 Asynchronous vs. Synchronous Concurrency Synchronous Partition state: S = S 1... S n T i : S S i Overall system: T (s, s ) n T i (s, s (i) ) i=0 Each process can perform a step in each transition Asynchronous Transition relation for each process: T i : S S Overall system: T (s, s ) i.t i (s, s ) Only one process performs a step in a transition D. Kroening: SSFT1 Verifying Concurrent Programs

6 Asynchronous Shared-Variable Concurrency We focus on asynchronous shared-variable concurrency Motivated by Intel s multi-core story Doubling the gate count doubles the power consumption Increasing the clock speed requires raising voltage, with manifold increase in power! Scaling micro-processors is easier by replicating CPU cores CPUs with 100 cores are around D. Kroening: SSFT1 Verifying Concurrent Programs

7 Thread Interleavings: Example (1) XX Thread 1 Thread Thread x=10; y++; y=0; x++; y++; Current state: x=0, y=0 D. Kroening: SSFT1 Verifying Concurrent Programs 7

8 Thread Interleavings: Example (1) XX Thread 1 Thread Thread x=10; y++; y=0; x++; y++; Current state: x=10, y=0 D. Kroening: SSFT1 Verifying Concurrent Programs 7

9 Thread Interleavings: Example (1) XX Thread 1 Thread Thread x=10; y++; y=0; x++; y++; Current state: x=10, y=1 D. Kroening: SSFT1 Verifying Concurrent Programs 7

10 Thread Interleavings: Example (1) XX Thread 1 Thread Thread x=10; y++; y=0; x++; y++; Current state: x=10, y=0 D. Kroening: SSFT1 Verifying Concurrent Programs 7

11 Thread Interleavings: Example (1) XX Thread 1 Thread Thread x=10; y++; y=0; x++; y++; Current state: x=11, y=0 D. Kroening: SSFT1 Verifying Concurrent Programs 7

12 Thread Interleavings: Example (1) XX Thread 1 Thread Thread x=10; y++; y=0; x++; y++; Current state: x=11, y=1 D. Kroening: SSFT1 Verifying Concurrent Programs 7

13 Thread Interleavings: Example () Alternative Schedule Thread 1 Thread Thread x=10; y++; y=0; x++; y++; Current state: x=0, y=0 D. Kroening: SSFT1 Verifying Concurrent Programs 8

14 Thread Interleavings: Example () Alternative Schedule Thread 1 Thread Thread x=10; y++; y=0; x++; y++; Current state: x=10, y=0 D. Kroening: SSFT1 Verifying Concurrent Programs 8

15 Thread Interleavings: Example () Alternative Schedule Thread 1 Thread Thread x=10; y++; y=0; x++; y++; Current state: x=11, y=0 D. Kroening: SSFT1 Verifying Concurrent Programs 8

16 Thread Interleavings: Example () Alternative Schedule Thread 1 Thread Thread x=10; y++; y=0; x++; y++; Current state: x=11, y=1 D. Kroening: SSFT1 Verifying Concurrent Programs 8

17 Thread Interleavings: Example () Alternative Schedule Thread 1 Thread Thread x=10; y++; y=0; x++; y++; Current state: x=11, y= D. Kroening: SSFT1 Verifying Concurrent Programs 8

18 Thread Interleavings: Example () Alternative Schedule Thread 1 Thread Thread x=10; y++; y=0; x++; y++; Current state: x=11, y=0 D. Kroening: SSFT1 Verifying Concurrent Programs 8

19 Races The example program has a race, i.e., the result depends on the schedule D. Kroening: SSFT1 Verifying Concurrent Programs 9

20 Races The example program has a race, i.e., the result depends on the schedule This may indicate a program bug, but need not Locks may help, but need not Enumerate? Exponential blowup! D. Kroening: SSFT1 Verifying Concurrent Programs 9

21 Ordering of Loads/Stores Thread 1 Thread mov [x], 1 mov [y], 1 mov eax, [y] mov ebx, [x] Suppose x and y are shared and initialized with 0 D. Kroening: SSFT1 Verifying Concurrent Programs 10

22 Ordering of Loads/Stores Thread 1 Thread mov [x], 1 mov [y], 1 mov eax, [y] mov ebx, [x] Suppose x and y are shared and initialized with 0 Unfortunately, the program may terminate with eax=ebx=0! D. Kroening: SSFT1 Verifying Concurrent Programs 10

23 Shared Memory in Hardware Computer vendors do not guarantee atomicity of loads/stores Only very special commands are guaranteed to be atomic, e.g., the Compare-and-Swap (CAS) instruction D. Kroening: SSFT1 Verifying Concurrent Programs 11

24 Shared Memory in Hardware Computer vendors do not guarantee atomicity of loads/stores Only very special commands are guaranteed to be atomic, e.g., the Compare-and-Swap (CAS) instruction Stores are not even guaranteed to be visible to other threads unless a memory barrier (memory fence) is inserted. But: memory fences are expensive (>100 cycles), so we cannot put them everywhere D. Kroening: SSFT1 Verifying Concurrent Programs 11

25 Boolean Programs Let s look at a Windows device driver example: 1 void DecrementIo(DEVICE OBJECT DeviceObject) { EXT ext = (EXT )DeviceObject >DeviceExtension; int IoIsPending = InterlockedDecrement (&ext >IoIsPending); 7 if (! IoIsPending) { 8 KeSetEvent (&ext >event, IO NO INCREMENT, FALSE); } 9 } D. Kroening: SSFT1 Verifying Concurrent Programs 1

26 Boolean Programs The initial abstraction, without any predicates: 1 void DecrementIo() { InterlockedDecrement(); goto L1,L; L1: KeSetEvent(); L: return; } D. Kroening: SSFT1 Verifying Concurrent Programs 1

27 Adding Some Predicates Some predicate refinement scheme computes a set of predicates: b1 ext == &envext b envext.ioispending == 1 b envext.ioispending == b IoIsPending == b IoIsPending == 1 b ( ext).ioispending == 1 b7 ( ext).ioispending == D. Kroening: SSFT1 Verifying Concurrent Programs 1

28 Boolean Programs This results in the following new abstract model: 1 bool b1,b,b; // global void DecrementIo() { bool b,b,b,b7; // local b1,b,b7 =,, constrain((!(b1 && b) b ) && 7 (!( b1 && b) b7 )); 8 b,b = InterlockedDecrement(b,b7); 9 goto L1,L; 10 L1: assume(!b &&!b); 11 KeSetEvent(); 1 L: return; 1 } D. Kroening: SSFT1 Verifying Concurrent Programs 1

29 Concurrent Boolean Programs Suppose we could dynamically create threads in Boolean Programs: 1 bool b1,b,b; // global void DecrementIo() { bool b,b,b,b7; // local b1,b,b7 =,, constrain((!(b1 && b) b ) && 7 (!( b1 && b) b7 )); 8 b,b = InterlockedDecrement(b,b7); 9 start thread L1, L; 10 L1: assume(!b &&!b); 11 KeSetEvent(); 1 L: return; 1 } D. Kroening: SSFT1 Verifying Concurrent Programs 1

30 Predicate Abstraction for Concurrent Programs Can we apply our refinement loop to concurrent software? C program 1.) Compute Abstraction.) Check Abstraction [no error] OK.) Refine Predicates.) Check Feasibility [feasible] report counterexample D. Kroening: SSFT1 Verifying Concurrent Programs 17

31 Predicate Abstraction for Concurrent Programs Claim: Yes, we can! Abstraction: as before! Checking ˆM: use Model Checker for concurrent Boolean programs Simulation: as before use thread switches from abstract counterexample Refinement: as before! D. Kroening: SSFT1 Verifying Concurrent Programs 18

32 Example 1 int g; void t1(void arg) { g=0; if (g==1) { g=; if (g==) 7 g=; 8 } 9 } 10 void t(void arg) { 11 g=1; 1 if (g==) { 1 g=; 1 assert(g!=); 1 } 1 } D. Kroening: SSFT1 Verifying Concurrent Programs 19

33 Example 1 int main() { 17 pthread t id1, id; pthread create(&id1, NULL, t1, NULL); 0 pthread create(&id, NULL, t, NULL); 1 } D. Kroening: SSFT1 Verifying Concurrent Programs 0

34 Initial Abstraction 1 decl g eq ; void t1() begin g eq :=0; // g=0; if then begin // g==1 g eq :=0; // g=; if then // g== 7 g eq :=1; // g=; 8 end 9 end 10 void t() begin 11 g eq :=0; // g=1; 1 if then begin // g== 1 g eq :=0; // g=; 1 assert(!g eq ); // g!= 1 end 1 end 17 void main() begin g eq :=0; start thread... end D. Kroening: SSFT1 Verifying Concurrent Programs 1

35 Abstract Counterexample Thread Line Instruction 0 19 g eq := 0; 11 g eq := 0; 1 if then... 1 g eq := 0; 1 g eq := 0; 1 if then... 1 g eq := 0; 1 if then g eq := 1; 1 assert(!g eq ); D. Kroening: SSFT1 Verifying Concurrent Programs

36 Abstract Counterexample Thread Line Instruction 0 19 g eq := 0; 11 g eq := 0; 1 if then... 1 g eq := 0; 1 g eq := 0; 1 if then... 1 g eq := 0; 1 if then g eq := 1; 1 assert(!g eq ); Concrete Instr. SSA-Constraint g=0; g 0 = 0 g=1; g 1 = 1 if (g==) g 1 = g=; g = g=0; g = 0 if (g==1) g = 1 g=; g = if (g==) g = g=; g = assert(g!=); g = D. Kroening: SSFT1 Verifying Concurrent Programs

37 Example In total, iterations, and predicates: g==, g==, g==1, g== Final counterexample has a thread switch after each assignment to g D. Kroening: SSFT1 Verifying Concurrent Programs

38 Tricky Details 1 volatile unsigned value; unsigned NonblockingCounter increment() { unsigned v = 0; lock (); 7 if (value == 0u 1) { 8 unlock(); 9 return 0; 10 }else{ 11 v = value; 1 value = v + 1; 1 unlock(); 1 assert(value > v); 1 return v + 1; 1 } 17 } D. Kroening: SSFT1 Verifying Concurrent Programs

39 Tricky Details 1 volatile unsigned value; unsigned NonblockingCounter increment() { unsigned v = 0; lock (); 7 if (value == 0u 1) { 8 unlock(); 9 return 0; 10 }else{ 11 v = value; 1 value = v + 1; 1 unlock(); 1 assert(value > v); 1 return v + 1; 1 } 17 } Is value>v global or local? D. Kroening: SSFT1 Verifying Concurrent Programs

40 Tricky Details 1 volatile unsigned value; unsigned NonblockingCounter increment() { unsigned v = 0; lock (); 7 if (value == 0u 1) { 8 unlock(); 9 return 0; 10 }else{ 11 v = value; 1 value = v + 1; 1 unlock(); 1 assert(value > v); 1 return v + 1; 1 } 17 } Is value>v global or local? CAV 011: neither. We need broadcast! D. Kroening: SSFT1 Verifying Concurrent Programs

41 The Problem We Consider Definition Consider thread state (s, l). thread state reachability problem: Is there a reachable global state (s, l 1,..., l n ) such that l = l i for some i? Note: can express single-index properties of threads can also encode MutEx: using shared variable as monitor D. Kroening: SSFT1 Verifying Concurrent Programs

42 Boolean Programs with Bounded Replication We have an effective Model Checker for Boolean programs with a bounded number of threads BDD-based Exploits symmetry between threads [CAV 009, FMSD 010] D. Kroening: SSFT1 Verifying Concurrent Programs

43 Symbolic Experiments [sec] [sec] Plain Symbolic Exploration Symbolic Boom with Counter Abstraction D. Kroening: SSFT1 Verifying Concurrent Programs 7

44 Boolean Programs with Unounded Replication But we really want an unbounded number of threads Programs with a large number of theads (>10) Server with dynamic thread spawning (say dependent on load) Or when thread-count is lost during predicate abstraction! Our answer: reduction to Petri net coverability D. Kroening: SSFT1 Verifying Concurrent Programs 8

45 Experimental Results 1. Boolean programs Proper concurrent ones (extracted from Linux kernel) Pseudo concurrent ones (SLAM). Petri Net benchmarks Bounded and unbounded Bingham and Ganty/Begin/Delzanno/Raskin Comparison with Lola (Karsten Wolf) and MIST D. Kroening: SSFT1 Verifying Concurrent Programs 9

46 Experimental Results On Boolean Programs: #P Sh Lcs Loc Time c Safe Unsafe ? We now need to make harder models! D. Kroening: SSFT1 Verifying Concurrent Programs 0

47 Experimental Results Checking coverability on standard Petri Net benchmarks: time (s) Comparison with numerous algorithms implemented in MIST #solved D. Kroening: SSFT1 Verifying Concurrent Programs 1

48 Experimental Results Checking coverability on Petri Nets with transfer arcs: time (s) #solved Comparison with two algorithms implemented in MIST D. Kroening: SSFT1 Verifying Concurrent Programs

49 Conclusion Model Checking for C programs with unbounded threads Symmetry-aware abstraction to VASS/Petri net coverability (with transfer arcs) Enables verification of C programs with unbounded concurrency D. Kroening: SSFT1 Verifying Concurrent Programs

50 Watch the video! Download me! D. Kroening: SSFT1 Verifying Concurrent Programs

Duet: Static Analysis for Unbounded Parallelism

Duet: Static Analysis for Unbounded Parallelism Duet: Static Analysis for Unbounded Parallelism Azadeh Farzan and Zachary Kincaid University of Toronto Abstract. Duet is a static analysis tool for concurrent programs in which the number of executing

More information

Predicate Abstraction Daniel Kroening 1

Predicate Abstraction Daniel Kroening 1 Predicate Abstraction 20.1.2005 Daniel Kroening 1 Motivation Software has too many state variables State Space Explosion Graf/Saïdi 97: Predicate Abstraction Idea: Only keep track of predicates on data

More information

Bounded Model Checking with Parametric Data Structures

Bounded Model Checking with Parametric Data Structures Bounded Model Checking with Marc Herbstritt (joint work with Erika Ábrahám, Bernd Becker, Martin Steffen) www.avacs.org August 15 2006 4th International Workshop on Bounded Model Checking Context Automated

More information

Software Model Checking. Xiangyu Zhang

Software Model Checking. Xiangyu Zhang Software Model Checking Xiangyu Zhang Symbolic Software Model Checking CS510 S o f t w a r e E n g i n e e r i n g Symbolic analysis explicitly explores individual paths, encodes and resolves path conditions

More information

More on Verification and Model Checking

More on Verification and Model Checking More on Verification and Model Checking Wednesday Oct 07, 2015 Philipp Rümmer Uppsala University Philipp.Ruemmer@it.uu.se 1/60 Course fair! 2/60 Exam st October 21, 8:00 13:00 If you want to participate,

More information

IJIT: An API for Boolean Program Analysis with Just-in-Time Translation 1

IJIT: An API for Boolean Program Analysis with Just-in-Time Translation 1 IJIT: An API for Boolean Program Analysis with Just-in-Time Translation 1 Peizun Liu and Thomas Wahl Northeastern University, Boston, USA SEFM 2017, Trento, Italy September 06, 2017 1 This work is supported

More information

THREADS: (abstract CPUs)

THREADS: (abstract CPUs) CS 61 Scribe Notes (November 29, 2012) Mu, Nagler, Strominger TODAY: Threads, Synchronization - Pset 5! AT LONG LAST! Adversarial network pong handling dropped packets, server delays, overloads with connection

More information

Dynamic Cutoff Detection in Parameterized Concurrent Programs

Dynamic Cutoff Detection in Parameterized Concurrent Programs Dynamic Cutoff Detection in Parameterized Concurrent Programs Alexander Kaiser, Daniel Kroening, and Thomas Wahl Oxford University Computing Laboratory, United Kingdom Abstract. The verification problem

More information

Synchronising Threads

Synchronising Threads Synchronising Threads David Chisnall March 1, 2011 First Rule for Maintainable Concurrent Code No data may be both mutable and aliased Harder Problems Data is shared and mutable Access to it must be protected

More information

CS 510/13. Predicate Abstraction

CS 510/13. Predicate Abstraction CS 50/3 Predicate Abstraction Predicate Abstraction Extract a finite state model from an infinite state system Used to prove assertions or safety properties Successfully applied for verification of C programs

More information

CS533 Concepts of Operating Systems. Jonathan Walpole

CS533 Concepts of Operating Systems. Jonathan Walpole CS533 Concepts of Operating Systems Jonathan Walpole Introduction to Threads and Concurrency Why is Concurrency Important? Why study threads and concurrent programming in an OS class? What is a thread?

More information

Atomicity CS 2110 Fall 2017

Atomicity CS 2110 Fall 2017 Atomicity CS 2110 Fall 2017 Parallel Programming Thus Far Parallel programs can be faster and more efficient Problem: race conditions Solution: synchronization Are there more efficient ways to ensure the

More information

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University CS 333 Introduction to Operating Systems Class 3 Threads & Concurrency Jonathan Walpole Computer Science Portland State University 1 Process creation in UNIX All processes have a unique process id getpid(),

More information

Verification of Parameterized Concurrent Programs By Modular Reasoning about Data and Control

Verification of Parameterized Concurrent Programs By Modular Reasoning about Data and Control Verification of Parameterized Concurrent Programs By Modular Reasoning about Data and Control Zachary Kincaid Azadeh Farzan University of Toronto January 18, 2013 Z. Kincaid (U. Toronto) Modular Reasoning

More information

Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017

Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017 Operating Systems Lecture 4 - Concurrency and Synchronization Adrien Krähenbühl Master of Computer Science PUF - Hồ Chí Minh 2016/2017 Mutual exclusion Hardware solutions Semaphores IPC: Message passing

More information

CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio

CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio Fall 2017 1 Outline Inter-Process Communication (20) Threads

More information

Thread. Disclaimer: some slides are adopted from the book authors slides with permission 1

Thread. Disclaimer: some slides are adopted from the book authors slides with permission 1 Thread Disclaimer: some slides are adopted from the book authors slides with permission 1 IPC Shared memory Recap share a memory region between processes read or write to the shared memory region fast

More information

Software Model Checking. From Programs to Kripke Structures

Software Model Checking. From Programs to Kripke Structures Software Model Checking (in (in C or or Java) Java) Model Model Extraction 1: int x = 2; int y = 2; 2: while (y

More information

Review: Easy Piece 1

Review: Easy Piece 1 CS 537 Lecture 10 Threads Michael Swift 10/9/17 2004-2007 Ed Lazowska, Hank Levy, Andrea and Remzi Arpaci-Dussea, Michael Swift 1 Review: Easy Piece 1 Virtualization CPU Memory Context Switch Schedulers

More information

CS 31: Introduction to Computer Systems : Threads & Synchronization April 16-18, 2019

CS 31: Introduction to Computer Systems : Threads & Synchronization April 16-18, 2019 CS 31: Introduction to Computer Systems 22-23: Threads & Synchronization April 16-18, 2019 Making Programs Run Faster We all like how fast computers are In the old days (1980 s - 2005): Algorithm too slow?

More information

Typed Assembly Language for Implementing OS Kernels in SMP/Multi-Core Environments with Interrupts

Typed Assembly Language for Implementing OS Kernels in SMP/Multi-Core Environments with Interrupts Typed Assembly Language for Implementing OS Kernels in SMP/Multi-Core Environments with Interrupts Toshiyuki Maeda and Akinori Yonezawa University of Tokyo Quiz [Environment] CPU: Intel Xeon X5570 (2.93GHz)

More information

Synchronization for Concurrent Tasks

Synchronization for Concurrent Tasks Synchronization for Concurrent Tasks Minsoo Ryu Department of Computer Science and Engineering 2 1 Race Condition and Critical Section Page X 2 Algorithmic Approaches Page X 3 Hardware Support Page X 4

More information

F-Soft: Software Verification Platform

F-Soft: Software Verification Platform F-Soft: Software Verification Platform F. Ivančić, Z. Yang, M.K. Ganai, A. Gupta, I. Shlyakhter, and P. Ashar NEC Laboratories America, 4 Independence Way, Suite 200, Princeton, NJ 08540 fsoft@nec-labs.com

More information

SPIN, PETERSON AND BAKERY LOCKS

SPIN, PETERSON AND BAKERY LOCKS Concurrent Programs reasoning about their execution proving correctness start by considering execution sequences CS4021/4521 2018 jones@scss.tcd.ie School of Computer Science and Statistics, Trinity College

More information

Foundations of the C++ Concurrency Memory Model

Foundations of the C++ Concurrency Memory Model Foundations of the C++ Concurrency Memory Model John Mellor-Crummey and Karthik Murthy Department of Computer Science Rice University johnmc@rice.edu COMP 522 27 September 2016 Before C++ Memory Model

More information

Symmetry-Aware Predicate Abstraction for Shared-Variable Concurrent Programs

Symmetry-Aware Predicate Abstraction for Shared-Variable Concurrent Programs Symmetry-Aware Predicate Abstraction for Shared-Variable Concurrent Programs Alastair Donaldson, Alexander Kaiser, Daniel Kroening, and Thomas Wahl Computer Science Department, Oxford University, United

More information

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University CS 333 Introduction to Operating Systems Class 3 Threads & Concurrency Jonathan Walpole Computer Science Portland State University 1 The Process Concept 2 The Process Concept Process a program in execution

More information

The ComFoRT Reasoning Framework

The ComFoRT Reasoning Framework Pittsburgh, PA 15213-3890 The ComFoRT Reasoning Framework Sagar Chaki James Ivers Natasha Sharygina Kurt Wallnau Predictable Assembly from Certifiable Components Enable the development of software systems

More information

COREMU: a Portable and Scalable Parallel Full-system Emulator

COREMU: a Portable and Scalable Parallel Full-system Emulator COREMU: a Portable and Scalable Parallel Full-system Emulator Haibo Chen Parallel Processing Institute Fudan University http://ppi.fudan.edu.cn/haibo_chen Full-System Emulator Useful tool for multicore

More information

Sliced Path Prefixes: An Effective Method to Enable Refinement Selection

Sliced Path Prefixes: An Effective Method to Enable Refinement Selection FORTE '15 Sliced Path Prefixes: An Effective Method to Enable Refinement Selection Dirk Beyer, Stefan Löwe, Philipp Wendler SoSy-Lab Software Systems We want Refinement Selection!!! Because straight-forward

More information

Synchronization COMPSCI 386

Synchronization COMPSCI 386 Synchronization COMPSCI 386 Obvious? // push an item onto the stack while (top == SIZE) ; stack[top++] = item; // pop an item off the stack while (top == 0) ; item = stack[top--]; PRODUCER CONSUMER Suppose

More information

The University of Texas at Arlington

The University of Texas at Arlington The University of Texas at Arlington Lecture 10: Threading and Parallel Programming Constraints CSE 5343/4342 Embedded d Systems II Objectives: Lab 3: Windows Threads (win32 threading API) Convert serial

More information

Introduction to PThreads and Basic Synchronization

Introduction to PThreads and Basic Synchronization Introduction to PThreads and Basic Synchronization Michael Jantz, Dr. Prasad Kulkarni Dr. Douglas Niehaus EECS 678 Pthreads Introduction Lab 1 Introduction In this lab, we will learn about some basic synchronization

More information

Programming in Parallel COMP755

Programming in Parallel COMP755 Programming in Parallel COMP755 All games have morals; and the game of Snakes and Ladders captures, as no other activity can hope to do, the eternal truth that for every ladder you hope to climb, a snake

More information

Concurrency. Johan Montelius KTH

Concurrency. Johan Montelius KTH Concurrency Johan Montelius KTH 2017 1 / 32 What is concurrency? 2 / 32 What is concurrency? Concurrency: (the illusion of) happening at the same time. 2 / 32 What is concurrency? Concurrency: (the illusion

More information

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks

More information

The Spin Model Checker : Part I/II

The Spin Model Checker : Part I/II The Spin Model Checker : Part I/II Moonzoo Kim CS Dept. KAIST Korea Advanced Institute of Science and Technology Motivation: Tragic Accidents Caused by SW Bugs 2 Cost of Software Errors June 2002 Software

More information

What is concurrency? Concurrency. What is parallelism? concurrency vs parallelism. Concurrency: (the illusion of) happening at the same time.

What is concurrency? Concurrency. What is parallelism? concurrency vs parallelism. Concurrency: (the illusion of) happening at the same time. What is concurrency? Concurrency Johan Montelius KTH 2017 Concurrency: (the illusion of) happening at the same time. A property of the programing model. Why would we want to do things concurrently? What

More information

CS 153 Lab4 and 5. Kishore Kumar Pusukuri. Kishore Kumar Pusukuri CS 153 Lab4 and 5

CS 153 Lab4 and 5. Kishore Kumar Pusukuri. Kishore Kumar Pusukuri CS 153 Lab4 and 5 CS 153 Lab4 and 5 Kishore Kumar Pusukuri Outline Introduction A thread is a straightforward concept : a single sequential flow of control. In traditional operating systems, each process has an address

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Multithreading Multiprocessors Description Multiple processing units (multiprocessor) From single microprocessor to large compute clusters Can perform multiple

More information

Symbolic Execution, Dynamic Analysis

Symbolic Execution, Dynamic Analysis Symbolic Execution, Dynamic Analysis http://d3s.mff.cuni.cz Pavel Parízek CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Symbolic execution Pavel Parízek Symbolic Execution, Dynamic Analysis

More information

Having a BLAST with SLAM

Having a BLAST with SLAM Announcements Having a BLAST with SLAM Meetings -, CSCI 7, Fall 00 Moodle problems? Blog problems? Looked at the syllabus on the website? in program analysis Microsoft uses and distributes the Static Driver

More information

THREADS & CONCURRENCY

THREADS & CONCURRENCY 27/04/2018 Sorry for the delay in getting slides for today 2 Another reason for the delay: Yesterday: 63 posts on the course Piazza yesterday. A7: If you received 100 for correctness (perhaps minus a late

More information

CS 220: Introduction to Parallel Computing. Introduction to CUDA. Lecture 28

CS 220: Introduction to Parallel Computing. Introduction to CUDA. Lecture 28 CS 220: Introduction to Parallel Computing Introduction to CUDA Lecture 28 Today s Schedule Project 4 Read-Write Locks Introduction to CUDA 5/2/18 CS 220: Parallel Computing 2 Today s Schedule Project

More information

On Reasoning about Finite Sets in Software Checking

On Reasoning about Finite Sets in Software Checking On Reasoning about Finite Sets in Software Model Checking Pavel Shved Institute for System Programming, RAS SYRCoSE 2 June 2010 Static Program Verification Static Verification checking programs against

More information

Systèmes d Exploitation Avancés

Systèmes d Exploitation Avancés Systèmes d Exploitation Avancés Instructor: Pablo Oliveira ISTY Instructor: Pablo Oliveira (ISTY) Systèmes d Exploitation Avancés 1 / 32 Review : Thread package API tid thread create (void (*fn) (void

More information

INF672 Protocol Safety and Verification. Karthik Bhargavan Xavier Rival Thomas Clausen

INF672 Protocol Safety and Verification. Karthik Bhargavan Xavier Rival Thomas Clausen INF672 Protocol Safety and Verication Karthik Bhargavan Xavier Rival Thomas Clausen 1 Course Outline Lecture 1 [Today, Sep 15] Introduction, Motivating Examples Lectures 2-4 [Sep 22,29, Oct 6] Network

More information

Synchronization. Disclaimer: some slides are adopted from the book authors slides with permission 1

Synchronization. Disclaimer: some slides are adopted from the book authors slides with permission 1 Synchronization Disclaimer: some slides are adopted from the book authors slides with permission 1 What is it? Recap: Thread Independent flow of control What does it need (thread private)? Stack What for?

More information

Lecture 2: Symbolic Model Checking With SAT

Lecture 2: Symbolic Model Checking With SAT Lecture 2: Symbolic Model Checking With SAT Edmund M. Clarke, Jr. School of Computer Science Carnegie Mellon University Pittsburgh, PA 15213 (Joint work over several years with: A. Biere, A. Cimatti, Y.

More information

Intel Threading Tools

Intel Threading Tools Intel Threading Tools Paul Petersen, Intel -1- INFORMATION IN THIS DOCUMENT IS PROVIDED IN CONNECTION WITH INTEL PRODUCTS. EXCEPT AS PROVIDED IN INTEL'S TERMS AND CONDITIONS OF SALE FOR SUCH PRODUCTS,

More information

CROWDMARK. Examination Midterm. Spring 2017 CS 350. Closed Book. Page 1 of 30. University of Waterloo CS350 Midterm Examination.

CROWDMARK. Examination Midterm. Spring 2017 CS 350. Closed Book. Page 1 of 30. University of Waterloo CS350 Midterm Examination. Times: Thursday 2017-06-22 at 19:00 to 20:50 (7 to 8:50PM) Duration: 1 hour 50 minutes (110 minutes) Exam ID: 3520593 Please print in pen: Waterloo Student ID Number: WatIAM/Quest Login Userid: Sections:

More information

Synchronizing the Asynchronous

Synchronizing the Asynchronous Synchronizing the Asynchronous Bernhard Kragl IST Austria Shaz Qadeer Microsoft Thomas A. Henzinger IST Austria Concurrency is Ubiquitous Asynchronous Concurrency is Ubiquitous Asynchronous programs are

More information

C09: Process Synchronization

C09: Process Synchronization CISC 7310X C09: Process Synchronization Hui Chen Department of Computer & Information Science CUNY Brooklyn College 3/29/2018 CUNY Brooklyn College 1 Outline Race condition and critical regions The bounded

More information

Having a BLAST with SLAM

Having a BLAST with SLAM Having a BLAST with SLAM # #2 Topic: Software Model Checking via Counter-Example Guided Abstraction Refinement There are easily two dozen SLAM/BLAST/MAGIC papers; I will skim. #3 SLAM Overview INPUT: Program

More information

Recap: Thread. What is it? What does it need (thread private)? What for? How to implement? Independent flow of control. Stack

Recap: Thread. What is it? What does it need (thread private)? What for? How to implement? Independent flow of control. Stack What is it? Recap: Thread Independent flow of control What does it need (thread private)? Stack What for? Lightweight programming construct for concurrent activities How to implement? Kernel thread vs.

More information

Process Synchronization (Part I)

Process Synchronization (Part I) Process Synchronization (Part I) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic) Amir H. Payberah (Tehran Polytechnic) Process Synchronization 1393/7/14 1 / 44 Motivation

More information

CS 111. Operating Systems Peter Reiher

CS 111. Operating Systems Peter Reiher Operating System Principles: Mutual Exclusion and Asynchronous Completion Operating Systems Peter Reiher Page 1 Outline Mutual Exclusion Asynchronous Completions Page 2 Mutual Exclusion Critical sections

More information

Action Language Verifier, Extended

Action Language Verifier, Extended Action Language Verifier, Extended Tuba Yavuz-Kahveci 1, Constantinos Bartzis 2, and Tevfik Bultan 3 1 University of Florida 2 Carnegie Mellon University 3 UC, Santa Barbara 1 Introduction Action Language

More information

Static Analysis of Embedded C

Static Analysis of Embedded C Static Analysis of Embedded C John Regehr University of Utah Joint work with Nathan Cooprider Motivating Platform: TinyOS Embedded software for wireless sensor network nodes Has lots of SW components for

More information

CS5460: Operating Systems

CS5460: Operating Systems CS5460: Operating Systems Lecture 9: Implementing Synchronization (Chapter 6) Multiprocessor Memory Models Uniprocessor memory is simple Every load from a location retrieves the last value stored to that

More information

Martin Kruliš, v

Martin Kruliš, v Martin Kruliš 1 Optimizations in General Code And Compilation Memory Considerations Parallelism Profiling And Optimization Examples 2 Premature optimization is the root of all evil. -- D. Knuth Our goal

More information

Kernel Synchronization I. Changwoo Min

Kernel Synchronization I. Changwoo Min 1 Kernel Synchronization I Changwoo Min 2 Summary of last lectures Tools: building, exploring, and debugging Linux kernel Core kernel infrastructure syscall, module, kernel data structures Process management

More information

Synchronization: Basics

Synchronization: Basics Synchronization: Basics 53: Introduction to Computer Systems 4 th Lecture, April 8, 7 Instructor: Seth Copen Goldstein, Franz Franchetti Today Threads review Sharing Mutual exclusion Semaphores Traditional

More information

Multithreading Programming II

Multithreading Programming II Multithreading Programming II Content Review Multithreading programming Race conditions Semaphores Thread safety Deadlock Review: Resource Sharing Access to shared resources need to be controlled to ensure

More information

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition Synchronization: Basics 53: Introduction to Computer Systems 4 th Lecture, November 6, 7 Instructor: Randy Bryant Today Threads review Sharing Mutual exclusion Semaphores 3 Traditional View of a Process

More information

Having a BLAST with SLAM

Having a BLAST with SLAM Having a BLAST with SLAM Meeting, CSCI 555, Fall 20 Announcements Homework 0 due Sat Questions? Move Tue office hours to -5pm 2 Software Model Checking via Counterexample Guided Abstraction Refinement

More information

Parallel Programming Languages COMP360

Parallel Programming Languages COMP360 Parallel Programming Languages COMP360 The way the processor industry is going, is to add more and more cores, but nobody knows how to program those things. I mean, two, yeah; four, not really; eight,

More information

CIS Operating Systems Synchronization based on Busy Waiting. Professor Qiang Zeng Spring 2018

CIS Operating Systems Synchronization based on Busy Waiting. Professor Qiang Zeng Spring 2018 CIS 3207 - Operating Systems Synchronization based on Busy Waiting Professor Qiang Zeng Spring 2018 Previous class IPC for passing data Pipe FIFO Message Queue Shared Memory Compare these IPCs for data

More information

Actor-Based Concurrency: Implementation and Comparative Analysis With Shared Data and Locks Alex Halter Randy Shepherd

Actor-Based Concurrency: Implementation and Comparative Analysis With Shared Data and Locks Alex Halter Randy Shepherd Actor-Based Concurrency: Implementation and Comparative Analysis With Shared Data and Locks Alex Halter Randy Shepherd 1. Introduction Writing correct concurrent programs using shared data and locks is

More information

Dept. of CSE, York Univ. 1

Dept. of CSE, York Univ. 1 EECS 3221.3 Operating System Fundamentals No.5 Process Synchronization(1) Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University Background: cooperating processes with shared

More information

Having a BLAST with SLAM

Having a BLAST with SLAM Having a BLAST with SLAM # #2 Topic: Software Model Checking via Counter-Example Guided Abstraction Refinement There are easily two dozen SLAM/BLAST/MAGIC papers; I will skim. #3 SLAM Overview INPUT: Program

More information

CMSC421: Principles of Operating Systems

CMSC421: Principles of Operating Systems CMSC421: Principles of Operating Systems Nilanjan Banerjee Assistant Professor, University of Maryland Baltimore County nilanb@umbc.edu http://www.csee.umbc.edu/~nilanb/teaching/421/ Principles of Operating

More information

An Introduction to Parallel Systems

An Introduction to Parallel Systems Lecture 4 - Shared Resource Parallelism University of Bath December 6, 2007 When Week 1 Introduction Who, What, Why, Where, When? Week 2 Data Parallelism and Vector Processors Week 3 Message Passing Systems

More information

CS 475. Process = Address space + one thread of control Concurrent program = multiple threads of control

CS 475. Process = Address space + one thread of control Concurrent program = multiple threads of control Processes & Threads Concurrent Programs Process = Address space + one thread of control Concurrent program = multiple threads of control Multiple single-threaded processes Multi-threaded process 2 1 Concurrent

More information

Lecture 5 Threads and Pthreads II

Lecture 5 Threads and Pthreads II CSCI-GA.3033-017 Special Topics: Multicore Programming Lecture 5 Threads and Pthreads II Christopher Mitchell, Ph.D. cmitchell@cs.nyu.edu http://z80.me Context We re exploring the layers of an application

More information

The Java Memory Model

The Java Memory Model Jeremy Manson 1, William Pugh 1, and Sarita Adve 2 1 University of Maryland 2 University of Illinois at Urbana-Champaign Presented by John Fisher-Ogden November 22, 2005 Outline Introduction Sequential

More information

Cache Coherence and Atomic Operations in Hardware

Cache Coherence and Atomic Operations in Hardware Cache Coherence and Atomic Operations in Hardware Previously, we introduced multi-core parallelism. Today we ll look at 2 things: 1. Cache coherence 2. Instruction support for synchronization. And some

More information

Model Checking Embedded C Software using k-induction and Invariants

Model Checking Embedded C Software using k-induction and Invariants FEDERAL UNIVERSITY OF RORAIMA and FEDERAL UNIVESITY OF AMAZONAS Model Checking Embedded C Software using k-induction and Invariants Herbert Rocha, Hussama Ismail, Lucas Cordeiro and Raimundo Barreto Agenda

More information

Lecture 10 Midterm review

Lecture 10 Midterm review Lecture 10 Midterm review Announcements The midterm is on Tue Feb 9 th in class 4Bring photo ID 4You may bring a single sheet of notebook sized paper 8x10 inches with notes on both sides (A4 OK) 4You may

More information

Synchronization: Basics

Synchronization: Basics Synchronization: Basics CS 485G6: Systems Programming Lecture 34: 5 Apr 6 Shared Variables in Threaded C Programs Question: Which variables in a threaded C program are shared? The answer is not as simple

More information

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

INF 212 ANALYSIS OF PROG. LANGS CONCURRENCY. Instructors: Crista Lopes Copyright Instructors. INF 212 ANALYSIS OF PROG. LANGS CONCURRENCY Instructors: Crista Lopes Copyright Instructors. Basics Concurrent Programming More than one thing at a time Examples: Network server handling hundreds of clients

More information

CS4961 Parallel Programming. Lecture 12: Advanced Synchronization (Pthreads) 10/4/11. Administrative. Mary Hall October 4, 2011

CS4961 Parallel Programming. Lecture 12: Advanced Synchronization (Pthreads) 10/4/11. Administrative. Mary Hall October 4, 2011 CS4961 Parallel Programming Lecture 12: Advanced Synchronization (Pthreads) Mary Hall October 4, 2011 Administrative Thursday s class Meet in WEB L130 to go over programming assignment Midterm on Thursday

More information

Concurrency: Mutual Exclusion and

Concurrency: Mutual Exclusion and Concurrency: Mutual Exclusion and Synchronization 1 Needs of Processes Allocation of processor time Allocation and sharing resources Communication among processes Synchronization of multiple processes

More information

Agenda. Highlight issues with multi threaded programming Introduce thread synchronization primitives Introduce thread safe collections

Agenda. Highlight issues with multi threaded programming Introduce thread synchronization primitives Introduce thread safe collections Thread Safety Agenda Highlight issues with multi threaded programming Introduce thread synchronization primitives Introduce thread safe collections 2 2 Need for Synchronization Creating threads is easy

More information

CPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.

CPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts. CPSC/ECE 3220 Fall 2017 Exam 1 Name: 1. Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.) Referee / Illusionist / Glue. Circle only one of R, I, or G.

More information

Verifying C & C++ with ESBMC

Verifying C & C++ with ESBMC Verifying C & C++ with ESBMC Denis A Nicole dan@ecs.soton.ac.uk CyberSecuritySoton.org [w] @CybSecSoton [fb & tw] ESBMC ESBMC, the Efficient SMT-Based Context-Bounded Model Checker was originally developed

More information

Binary Decision Diagrams and Symbolic Model Checking

Binary Decision Diagrams and Symbolic Model Checking Binary Decision Diagrams and Symbolic Model Checking Randy Bryant Ed Clarke Ken McMillan Allen Emerson CMU CMU Cadence U Texas http://www.cs.cmu.edu/~bryant Binary Decision Diagrams Restricted Form of

More information

Static Program Analysis

Static Program Analysis Static Program Analysis Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ws-1617/spa/ Schedule of Lectures Jan 17/19: Interprocedural DFA

More information

Intro to Threads. Two approaches to concurrency. Threaded multifinger: - Asynchronous I/O (lab) - Threads (today s lecture)

Intro to Threads. Two approaches to concurrency. Threaded multifinger: - Asynchronous I/O (lab) - Threads (today s lecture) Intro to Threads Two approaches to concurrency - Asynchronous I/O (lab) - Threads (today s lecture) Threaded multifinger: - Run many copies of finger simultaneously for (int i = 1; i < argc; i++) thread_create

More information

Sistemi in tempo reale Anno accademico

Sistemi in tempo reale Anno accademico Sistemi in tempo reale Anno accademico 2006-2007 Concorrenza - II Giuseppe Lipari http://feanor.sssup.it/~lipari Scuola Superiore Sant Anna Outline 1 Introduction to concurrency 2 Models of concurrency:

More information

Synchronization 1. Synchronization

Synchronization 1. Synchronization Synchronization 1 Synchronization key concepts critical sections, mutual exclusion, test-and-set, spinlocks, blocking and blocking locks, semaphores, condition variables, deadlocks reading Three Easy Pieces:

More information

Verifying Multithreaded Software with Impact

Verifying Multithreaded Software with Impact Verifying Multithreaded Software with Impact Björn Wachter, Daniel Kroening and Joël Ouaknine University of Oxford Intro Multi-threading C/C++ with POSIX/WIN 32 threads event processing, device drivers,

More information

Synchronization II: EventBarrier, Monitor, and a Semaphore. COMPSCI210 Recitation 4th Mar 2013 Vamsi Thummala

Synchronization II: EventBarrier, Monitor, and a Semaphore. COMPSCI210 Recitation 4th Mar 2013 Vamsi Thummala Synchronization II: EventBarrier, Monitor, and a Semaphore COMPSCI210 Recitation 4th Mar 2013 Vamsi Thummala Check point: Mission in progress Master synchronization techniques Develop best practices for

More information

Configurable Software Model Checking

Configurable Software Model Checking Configurable Software Model Checking CPAchecker Dirk Beyer Dirk Beyer 1 / 26 Software Verification C Program int main() { int a = foo(); int b = bar(a); } assert(a == b); Verification Tool TRUE i.e., specification

More information

Real-Time and Concurrent Programming Lecture 4 (F4): Monitors: synchronized, wait and notify

Real-Time and Concurrent Programming Lecture 4 (F4): Monitors: synchronized, wait and notify http://cs.lth.se/eda040 Real-Time and Concurrent Programming Lecture 4 (F4): Monitors: synchronized, wait and notify Klas Nilsson 2016-09-20 http://cs.lth.se/eda040 F4: Monitors: synchronized, wait and

More information

No model may be available. Software Abstractions. Recap on Model Checking. Model Checking for SW Verif. More on the big picture. Abst -> MC -> Refine

No model may be available. Software Abstractions. Recap on Model Checking. Model Checking for SW Verif. More on the big picture. Abst -> MC -> Refine No model may be available Programmer Software Abstractions Tests Coverage Code Abhik Roychoudhury CS 5219 National University of Singapore Testing Debug Today s lecture Abstract model (Boolean pgm.) Desirable

More information

Synchronization. CS61, Lecture 18. Prof. Stephen Chong November 3, 2011

Synchronization. CS61, Lecture 18. Prof. Stephen Chong November 3, 2011 Synchronization CS61, Lecture 18 Prof. Stephen Chong November 3, 2011 Announcements Assignment 5 Tell us your group by Sunday Nov 6 Due Thursday Nov 17 Talks of interest in next two days Towards Predictable,

More information

Concurrency & Parallelism. Threads, Concurrency, and Parallelism. Multicore Processors 11/7/17

Concurrency & Parallelism. Threads, Concurrency, and Parallelism. Multicore Processors 11/7/17 Concurrency & Parallelism So far, our programs have been sequential: they do one thing after another, one thing at a. Let s start writing programs that do more than one thing at at a. Threads, Concurrency,

More information

The Java Memory Model

The Java Memory Model The Java Memory Model What is it and why would I want one? Jörg Domaschka. ART Group, Institute for Distributed Systems Ulm University, Germany December 14, 2009 public class WhatDoIPrint{ static int x

More information

Today. Threads review Sharing Mutual exclusion Semaphores

Today. Threads review Sharing Mutual exclusion Semaphores SYNCHRONIZATION Today Threads review Sharing Mutual exclusion Semaphores Process: Traditional View Process = process context + code, data, and stack Process context Program context: Data registers Condition

More information