Concurrency EECS /36

Similar documents
Shared Mutable State SWEN-220

i219 Software Design Methodology 12. Case study 1 Dining philosopher problem Kazuhiro Ogata (JAIST) Outline of lecture

Concurrent Object Oriented Languages

Space Exploration EECS /25

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Environment Modeling with JavaPathfinder (JPF) Part 3 - Lab

3C03 Concurrency: Starvation and Deadlocks

Sections 01 (11:30), 02 (16:00), 03 (8:30) Ashraf Aboulnaga & Borzoo Bonakdarpour

Processes The Process Model. Chapter 2. Processes and Threads. Process Termination. Process Creation

5 Classical IPC Problems

Contribution:javaMultithreading Multithreading Prof. Dr. Ralf Lämmel Universität Koblenz-Landau Software Languages Team

JVML Instruction Set. How to get more than 256 local variables! Method Calls. Example. Method Calls

Process Synchronization

JPF Lab Formal Methods Summer School 2011 Menlo College

Processes The Process Model. Chapter 2 Processes and Threads. Process Termination. Process States (1) Process Hierarchies

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

Code Profiling. CSE260, Computer Science B: Honors Stony Brook University

The dining philosophers problem. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 13

Java PathFinder. Pavel Parízek. CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics

Readers/Writers Problem. Readers/Writers: Scenario 1. Readers/Writers Problem. Today: Synchronization for Readers/Writers Problem

Chapter 7: Process Synchronization!

Deadlock. Concepts: Models: Practice: Aim: deadlock avoidance - to design systems where deadlock cannot occur. Chapter 6. Deadlock

Explain briefly how starvation may occur in process scheduling. (2 marks)

THREADS & CONCURRENCY

CSC 4320 Test 1 Spring 2017

2. The shared resource(s) in the dining philosophers problem is(are) a. forks. b. food. c. seats at a circular table.

Deadlock. INF2140 Parallel Programming: Lecture 6. March 07, INF2140 Parallel Programming: Lecture 6 Deadlock

Java Pathfinder. State of Affairs. Pavel Parizek. School of Computer Science, University of Waterloo

SFDV3006 Concurrent Programming

The Dining Philosophers Problem CMSC 330: Organization of Programming Languages

JPF Report System and Model Classes EECS /w/4315/

Concurrency: Deadlock 1. Magee/Kramer 2 nd Edition

The Java Language Implementation

CMSC 330: Organization of Programming Languages. The Dining Philosophers Problem

Multithreaded Programming Part II. CSE 219 Stony Brook University, Department of Computer Science

COMP 150-CCP Concurrent Programming. Lecture 12: Deadlock. Dr. Richard S. Hall

Verification of Java programs using networks of finite automata with discrete data.

Under the Hood: The Java Virtual Machine. Lecture 23 CS2110 Fall 2008

Semaphores (by Dijkstra)

Java Code Coverage Mechanics. by Evgeny Mandrikov at EclipseCon Europe 2017

SOFTWARE ARCHITECTURE 7. JAVA VIRTUAL MACHINE

Course Overview. PART I: overview material. PART II: inside a compiler. PART III: conclusion

CS 361 Concurrent programming Drexel University Spring 2000 Lecture 14. The dining philosophers problem

CMSC 330: Organization of Programming Languages. Threads Classic Concurrency Problems

Synchronization Principles II

Roadmap. Readers-Writers Problem. Readers-Writers Problem. Readers-Writers Problem (Cont.) Dining Philosophers Problem.

CS3502 OPERATING SYSTEMS

Dealing with Issues for Interprocess Communication

Java Code Coverage Mechanics Evgeny Mandrikov Marc Hoffmann #JokerConf 2017, Saint-Petersburg

Process Synchronization

Lecture Topics. Announcements. Today: Concurrency (Stallings, chapter , 5.7) Next: Exam #1. Self-Study Exercise #5. Project #3 (due 9/28)

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems

System Software. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 13

CSE 4/521 Introduction to Operating Systems

An Introduction to Multicodes. Ben Stephenson Department of Computer Science University of Western Ontario

An Introduction to Parallel Systems

Lecture 10: Multi-Object Synchronization

Chapter 6. Deadlock Concurrency: Deadlock. Magee/Kramer 2 nd Edition

Programming Languages

Paralleland Distributed Programming. Concurrency

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - XI Deadlocks - II. Louisiana State University

Roadmap. Bounded-Buffer Problem. Classical Problems of Synchronization. Bounded Buffer 1 Semaphore Soln. Bounded Buffer 1 Semaphore Soln. Tevfik Ko!

Process Management And Synchronization

Java Code Coverage Mechanics

CONCURRENT/DISTRIBUTED PROGRAMMING ILLUSTRATED USING THE DINING PHILOSOPHERS PROBLEM *

CSC 4181 Handout : JVM

Operating systems. Lecture 12

OS Process Synchronization!

Concept of a process

Static Analysis of Dynamic Languages. Jennifer Strater

Last Class: Synchronization Problems!

JVM. What This Topic is About. Course Overview. Recap: Interpretive Compilers. Abstract Machines. Abstract Machines. Class Files and Class File Format

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

Compilation 2012 Code Generation

Deadlock and Monitors. CS439: Principles of Computer Systems September 24, 2018

Chapter 7: Process Synchronization. Background. Illustration

Formal Methods for Java

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Threads & Concurrency

Threads & Concurrency

High Performance Computing Lecture 21. Matthew Jacob Indian Institute of Science

Multicore and Multiprocessor Systems: Part I

Synchronization. Peter J. Denning CS471/CS571. Copyright 2001, by Peter Denning

CS2110 Fall 2011 Lecture 25. Under the Hood: The Java Virtual Machine, Part II

Problem: Too Many Platforms!

Improving Java Performance

Chapter 2 Processes and Threads

i219 Software Design Methodology 11. Software model checking Kazuhiro Ogata (JAIST) Outline of lecture

Process Synchronization

Taming the Java Virtual Machine. Li Haoyi, Chicago Scala Meetup, 19 Apr 2017

Process Synchronization. studykorner.org

A Brief Introduction to OS/2 Multithreading

Deadlock Detection & recovery. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

Chapter 7: Process Synchronization. Background

Resource Allocation. Pradipta De

CSC501 Operating Systems Principles. Process Synchronization

Enforcing Mutual Exclusion Using Monitors

Process Synchronization

THREADS & CONCURRENCY

Transcription:

1/36 Concurrency EECS 4315 www.eecs.yorku.ca/course/4315/

Correct? 2/36 Question Is the developed class Database correct?

Correct? 2/36 Question Is the developed class Database correct? Answer Maybe.

Correct? 2/36 Question Is the developed class Database correct? Answer Maybe. Let us use JPF to try to find bugs in the Database class.

Configuration file 3/36 target=concurrency.readersandwriters classpath=/courses/4315/workspace/concurrency/bin/

JPF report 4/36 JavaPathfinder core system v8.0 (rev 2+) - (C) 2005-2014 Un ====================================================== syst concurrency.readersandwriters.main() ====================================================== sear ====================================================== resu no errors detected ====================================================== stat elapsed time: 00:00:11 states: new=28983,visited=64764,backtracked=93747 search: maxdepth=49,constraints=0 choice generators: thread=28983 (signal=2517,lock=8221,shar heap: new=400,released=157142,maxlive=386,gccyc instructions: 470903 max memory: 372MB loaded code: classes=61,methods=1381 ====================================================== sear

No writer 5/36 Question How can we use JPF to check that there is no writer writing when a reader is reading?

No writer 5/36 Question How can we use JPF to check that there is no writer writing when a reader is reading? Answer Add assert!this.writing in the read method where the database is read. If the assertion fails, an exception is thrown. JPF detects exceptions that are thrown and not caught.

JPF report JavaPathfinder core system v8.0 (rev 2+) - (C) 2005-2014 Un ====================================================== syst concurrency.readersandwriters.main() ====================================================== sear ====================================================== erro gov.nasa.jpf.vm.nouncaughtexceptionsproperty java.lang.assertionerror at concurrency.database.read(concurrency/database.java:28) at concurrency.reader.run(concurrency/reader.java:25) ====================================================== snap thread concurrency.reader:{id:2,name:thread-2,status:runnin call stack: at concurrency.database.read(database.java:28) at concurrency.reader.run(reader.java:25) thread concurrency.writer:{id:4,name:thread-4,status:runnin call stack: 6/36

Smallest instance 7/36 Try to find the smallest instance for which the error occurs.

Smallest instance 7/36 Try to find the smallest instance for which the error occurs. READER = 1 WRITERS = 1 no errors detected READER = 2 WRITERS = 1 no errors detected READER = 1 WRITERS = 2 error

Locating the error 8/36 ====================================================== erro gov.nasa.jpf.vm.nouncaughtexceptionsproperty java.lang.assertionerror at concurrency.database.read(concurrency/database.java:28) at concurrency.reader.run(concurrency/reader.java:25) Line 28 of the Database class. assert!this.writing;

Locating the error 9/36 ====================================================== snap thread concurrency.reader:{id:1,name:thread-1,status:runnin call stack: at concurrency.database.read(database.java:28) at concurrency.reader.run(reader.java:25) thread concurrency.writer:{id:3,name:thread-3,status:runnin call stack: at concurrency.database.beginwrite(database.java:78) at concurrency.database.write(database.java:61) at concurrency.writer.run(writer.java:25) A Reader thread is at line 28 of the Database class (assertion), while a Writer thread is at line 78 of the Database class (end of beginwrite).

Locating the error 10/36 Question How can we get a more detailed report?

Locating the error 10/36 Question How can we get a more detailed report? Answer By configuring the report.

11/36 report.class=gov.nasa.jpf.report.reporter report.publisher=console console is a symbolic name and the default value for the property report.publisher. The other values currently supported for this property are html and xml.

12/36 The symbolic name console is part of the following properties. report.console.class=gov.nasa.jpf.report.reporter report.console.start= report.console.transition= report.console.constraint= report.console.probe= report.console.property_violation= report.console.show_steps= report.console.show_method= report.console.show_code= report.console.finished= This configuration produces no output.

13/36 report.console.class=gov.nasa.jpf.report.reporter report.console.start=jpf report.console.transition= report.console.constraint= report.console.probe= report.console.property_violation= report.console.show_steps= report.console.show_method= report.console.show_code= report.console.finished= This configuration produces the following output. JavaPathfinder core system v8.0 (rev 2+) - (C) 2005-2014 Un ============================================ search started

14/36 report.console.class=gov.nasa.jpf.report.reporter report.console.start=sut report.console.transition= report.console.constraint= report.console.probe= report.console.property_violation= report.console.show_steps= report.console.show_method= report.console.show_code= report.console.finished= This configuration produces the following output. ============================================ system under t concurrency.readersandwriters.main() ============================================ search started

report.console.class=gov.nasa.jpf.report.reporter report.console.start=platform report.console.transition= report.console.constraint= report.console.probe= report.console.property_violation= report.console.show_steps= report.console.show_method= report.console.show_code= report.console.finished= This configuration produces the following output. ============================================ platform hostname: montreal arch: amd64/4 os: Windows 7/6.1 java: Oracle Corporation/1.8.0_25 15/36

16/36 report.console.class=gov.nasa.jpf.report.reporter report.console.start=dtg report.console.transition= report.console.constraint= report.console.probe= report.console.property_violation= report.console.show_steps= report.console.show_method= report.console.show_code= report.console.finished= This configuration produces the following output. started: Mon Mar 12 20:23:36 EDT 2018 ====================================================== sear

============================================ JPF configurat property source: E:\courses\4315\.jpf\site.properties property source: E:\courses\4315\jpf\jpf-core\jpf.propertie property source: E:\courses\4315\workspace\concurrency\src\ properties: 17/36 report.console.class=gov.nasa.jpf.report.reporter report.console.start=config report.console.transition= report.console.constraint= report.console.probe= report.console.property_violation= report.console.show_steps= report.console.show_method= report.console.show_code= report.console.finished= This configuration produces the following output.

============================================ error 1 gov.nasa.jpf.vm.nouncaughtexceptionsproperty java.lang.assertionerror at concurrency.database.read(concurrency/database.java:2 at concurrency.reader.run(concurrency/reader.java:25) 18/36 report.console.class=gov.nasa.jpf.report.reporter report.console.start= report.console.transition= report.console.constraint= report.console.probe= report.console.property_violation=error report.console.show_steps= report.console.show_method= report.console.show_code= report.console.finished= This configuration produces the following output.

19/36 report.console.class=gov.nasa.jpf.report.reporter report.console.start= report.console.transition= report.console.constraint= report.console.probe= report.console.property_violation=output report.console.show_steps= report.console.show_method= report.console.show_code= report.console.finished= This configuration produces the following output. ============================================ output #1 no output

============================================ snapshot #1 thread concurrency.reader:{id:1,name:thread-1,status:runnin call stack: at concurrency.database.read(database.java:28) at concurrency.reader.run(reader.java:25) 20/36 report.console.class=gov.nasa.jpf.report.reporter report.console.start= report.console.transition= report.console.constraint= report.console.probe= report.console.property_violation=snapshot report.console.show_steps= report.console.show_method= report.console.show_code= report.console.finished= This configuration produces the following output.

21/36 report.console.class=gov.nasa.jpf.report.reporter report.console.start= report.console.transition= report.console.constraint= report.console.probe= report.console.property_violation=trace report.console.show_steps=false report.console.show_method= report.console.show_code= report.console.finished=

============================================ trace #1 ------------------------------------------------------ tran gov.nasa.jpf.vm.choice.threadchoicefromset {id:"root",1/1, ------------------------------------------------------ tran gov.nasa.jpf.vm.choice.threadchoicefromset {id:"start",1/2 ------------------------------------------------------ tran gov.nasa.jpf.vm.choice.threadchoicefromset {id:"start",1/3 ------------------------------------------------------ tran gov.nasa.jpf.vm.choice.threadchoicefromset {id:"start",1/4 ------------------------------------------------------ tran gov.nasa.jpf.vm.choice.threadchoicefromset {id:"terminate" ------------------------------------------------------ tran gov.nasa.jpf.vm.choice.threadchoicefromset {id:"lock",2/3, ------------------------------------------------------ tran gov.nasa.jpf.vm.choice.threadchoicefromset {id:"lock",2/3, ------------------------------------------------------ tran gov.nasa.jpf.vm.choice.threadchoicefromset {id:"shared_obje 22/36

23/36 report.console.class=gov.nasa.jpf.report.reporter report.console.start= report.console.transition= report.console.constraint= report.console.probe= report.console.property_violation=trace report.console.show_steps=true report.console.show_method= report.console.show_code=false report.console.finished=

============================================ trace #1 ------------------------------------------------------ tran gov.nasa.jpf.vm.choice.threadchoicefromset {id:"root",1/1, [3701 insn w/o sources] ------------------------------------------------------ tran gov.nasa.jpf.vm.choice.threadchoicefromset {id:"start",1/2 [17 insn w/o sources] ------------------------------------------------------ tran gov.nasa.jpf.vm.choice.threadchoicefromset {id:"start",1/3 [11 insn w/o sources] ------------------------------------------------------ tran gov.nasa.jpf.vm.choice.threadchoicefromset {id:"start",1/4 [8 insn w/o sources] ------------------------------------------------------ tran gov.nasa.jpf.vm.choice.threadchoicefromset {id:"terminate" [7 insn w/o sources] ------------------------------------------------------ tran 24/36

25/36 report.console.class=gov.nasa.jpf.report.reporter report.console.start= report.console.transition= report.console.constraint= report.console.probe= report.console.property_violation=trace report.console.show_steps=true report.console.show_method=false report.console.show_code=true report.console.finished=

============================================ trace #1 gov.nasa.jpf.vm.choice.threadchoicefromset {id:"root",1/1, invokestatic java.lang.boolean.<clinit>()v new java.lang.boolean@bc dup iconst_1 invokespecial java.lang.boolean.<init>(z)v aload_0 invokespecial java.lang.object.<init>()v return java.lang.object.<init>()v aload_0 iload_1 putfield java.lang.boolean.value return java.lang.boolean.<init>(z)v putstatic java.lang.boolean.true new java.lang.boolean@bd dup 26/36

27/36 report.console.class=gov.nasa.jpf.report.reporter report.console.start= report.console.transition= report.console.constraint= report.console.probe= report.console.property_violation=trace report.console.show_steps=true report.console.show_method=true report.console.show_code=true report.console.finished=

============================================ trace #1 ------------------------------------------------------ tran gov.nasa.jpf.vm.choice.threadchoicefromset {id:"root",1/1, java.lang.boolean.[<clinit>] invokestatic java.lang.boolean.<clinit>()v java.lang.boolean.<clinit>()v new java.lang.boolean@bc dup iconst_1 invokespecial java.lang.boolean.<init>(z)v java.lang.boolean.<init>(z)v aload_0 invokespecial java.lang.object.<init>()v java.lang.object.<init>()v return java.lang.object.<init>()v java.lang.boolean.<init>(z)v aload_0 28/36

29/36 report.console.class=gov.nasa.jpf.report.reporter report.console.start= report.console.transition= report.console.constraint= report.console.probe= report.console.property_violation= report.console.show_steps= report.console.show_method= report.console.show_code= report.console.finished=result This configuration produces the following output. ============================================ results error #1: gov.nasa.jpf.vm.nouncaughtexceptionsproperty "jav at concurrency.database..." ============================================ search finishe

report.console.class=gov.nasa.jpf.report.reporter report.console.start= report.console.transition= report.console.constraint= report.console.probe= report.console.property_violation= report.console.show_steps= report.console.show_method= report.console.show_code= report.console.finished=statistics This configuration produces the following output. ============================================ statistics elapsed time: 00:00:01 states: new=395,visited=361,backtracked=733,end=2 search: maxdepth=29,constraints=0 choice generators: thread=394 (signal=41,lock=115,sharedref 30/36

31/36 report.console.class=gov.nasa.jpf.report.reporter report.console.start=jpf report.console.transition= report.console.constraint= report.console.probe= report.console.property_violation=error,trace report.console.show_steps=true report.console.show_method=true report.console.show_code=true report.console.finished=statistics

JavaPathfinder core system v8.0 (rev 2+) - (C) 2005-2014 Un ============================================ search started ============================================ error 1 gov.nasa.jpf.vm.nouncaughtexceptionsproperty java.lang.assertionerror at concurrency.database.read(concurrency/database.java:28 at concurrency.reader.run(concurrency/reader.java:25) ============================================ trace #1 -------------------------------------------- transition #0 gov.nasa.jpf.vm.choice.threadchoicefromset {id:"root",1/1, java.lang.boolean.[<clinit>] invokestatic java.lang.boolean.<clinit>()v java.lang.boolean.<clinit>()v... ============================================ statistics elapsed time: 00:00:01 states: new=395,visited=361,backtracked=733,end=2 32/36

The dining philosophers problem In the dining philosophers problem, due to Dijkstra, five philosophers are seated around a round table. Each philosopher has a plate of spaghetti. A philosopher needs two forks to eat it. The layout of the table is as follows. The life of a philosopher consists of alternative periods of eating and thinking. When philosophers get hungry, they try to pick up their left and right fork, one at a time, in either order. If successful in picking up both forks, the philosopher eats for a while, then puts down the forks and continues to think. 33/36

The dining philosophers problem 34/36 public class Philosopher extends Thread { private int id; private Table table; public Philosopher(int id, Table table) { this.id = id; this.table = table; } public void run() { while (true) { this.table.pickup(id); this.table.pickup(id + 1 % 5); // eat this.table.putdown(id); this.table.putdown(id + 1 % 5); } }

The dining philosophers problem 35/36 public class Table { public void pickup(int id) {... } public void putdown(int id) {... } }