Computer Science 483/580 Concurrent Programming Midterm Exam February 23, 2009



Similar documents
Java SE 7 Programming

Java SE 7 Programming

Java SE 7 Programming

Mutual Exclusion using Monitors

Why Threads Are A Bad Idea (for most purposes)

Crash Course in Java

Topics. Producing Production Quality Software. Concurrent Environments. Why Use Concurrency? Models of concurrency Concurrency in Java

CS11 Java. Fall Lecture 7

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Java SE 8 Programming

Monitors, Java, Threads and Processes

Trace-Based and Sample-Based Profiling in Rational Application Developer

Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 2 November 21, 2011 SOLUTIONS.

Parallel Programming

Fundamentals of Java Programming

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.

3C03 Concurrency: Condition Synchronisation

PLV Goldstein 315, Tuesdays and Thursdays, 6:00PM-7:50PM. Tuesdays and Thursdays, 4:00PM-5:30PM and 7:50PM 9:30PM at PLV G320

Monitoring Java enviroment / applications

Outline of this lecture G52CON: Concepts of Concurrency

Outline. Computer Science 331. Stack ADT. Definition of a Stack ADT. Stacks. Parenthesis Matching. Mike Jacobson

Getting Started with the Internet Communications Engine

Monitor Object. An Object Behavioral Pattern for Concurrent Programming. Douglas C. Schmidt

Java 2 Web Developer Certification Study Guide Natalie Levi

DIPLOMADO DE JAVA - OCA

Last Class: Semaphores

Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz

Performance rule violations usually result in increased CPU or I/O, time to fix the mistake, and ultimately, a cost to the business unit.

Principles of Software Construction: Objects, Design, and Concurrency. Course Introduction. toad. toad Fall School of Computer Science

This lecture. Abstract data types Stacks Queues. ADTs, Stacks, Queues Goodrich, Tamassia

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

Programming Embedded Systems

Real-world Java 4 beginners. Dima, Superfish github.com/dimafrid

: provid.ir

Parallel Computing in Python: multiprocessing. Konrad HINSEN Centre de Biophysique Moléculaire (Orléans) and Synchrotron Soleil (St Aubin)

Top 10 reasons your ecommerce site will fail during peak periods

The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0

Lecture Data Types and Types of a Language

Friendship and Encapsulation in C++

The end. Carl Nettelblad

Java Concurrency Framework. Sidartha Gracias

SSC - Concurrency and Multi-threading Java multithreading programming - Synchronisation (I)

Deadlock Victim. dimanche 6 mai 12

Replication on Virtual Machines

Concurrent Programming

Java Interview Questions and Answers

CHAPTER 4 ESSENTIAL DATA STRUCTRURES

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Fall 2007 Lecture 5 - DBMS Architecture

Overview Motivating Examples Interleaving Model Semantics of Correctness Testing, Debugging, and Verification

Weighted Total Mark. Weighted Exam Mark

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Performance Improvement In Java Application

Data Types. Abstract Data Types. ADTs as Design Tool. Abstract Data Types. Integer ADT. Principle of Abstraction

Resurrecting Ada s Rendez-Vous in Java

C++ INTERVIEW QUESTIONS

CS4410 Final Exam : Solution set. while(ticket[k] && (ticket[k],k) < (ticket[i],i))

Multi-core Programming System Overview

Sequence Diagrams. Massimo Felici. Massimo Felici Sequence Diagrams c

Java Coding Practices for Improved Application Performance

Threads 1. When writing games you need to do more than one thing at once.

Unit 8: Immutability & Actors

How To Understand And Understand An Operating System In C Programming

INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Built-in Concurrency Primitives in Java Programming Language. by Yourii Martiak and Mahir Atmis

Ambientes de Desenvolvimento Avançados

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

HW3: Programming with stacks

In This Lecture. More Concurrency. Deadlocks. Precedence/Wait-For Graphs. Example. Example

3 - Lift with Monitors

Write Barrier Removal by Static Analysis

Developing Task Model Applications

Getting Started with Multithreaded Perl

Performance Monitoring and Visualization of Large-Sized and Multi- Threaded Applications with the Pajé Framework

Design Patterns in C++

Java from a C perspective. Plan

TDA - Thread Dump Analyzer

Software and the Concurrency Revolution

RVS-Seminar Implementation and Evaluation of WinJTAP Interface. Milan Nikolic Universität Bern

Monitors and Exceptions : How to Implement Java efficiently. Andreas Krall and Mark Probst Technische Universitaet Wien

Class 32: The Java Collections Framework

Unit 6: Conditions, Barriers, and RendezVous

Advanced Multiprocessor Programming

Spring 2011 Prof. Hyesoon Kim

Extreme Performance with Java

CSCI E 98: Managed Environments for the Execution of Programs

HP NonStop JDBC Type 4 Driver Performance Tuning Guide for Version 1.0

Debugging with TotalView

Historically, Huge Performance Gains came from Huge Clock Frequency Increases Unfortunately.

Priority Inversion Problem and Deadlock Situations

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

A Comparison Of Shared Memory Parallel Programming Models. Jace A Mogill David Haglin

SQL Server. SQL Server 100 Most Asked Questions: Best Practices guide to managing, mining, building and developing SQL Server databases

Contents. 9-1 Copyright (c) N. Afshartous

Spark ΕΡΓΑΣΤΗΡΙΟ 10. Prepared by George Nikolaides 4/19/2015 1

E) Modeling Insights: Patterns and Anti-patterns

Operating Systems and Networks

Chapter 6, The Operating System Machine Level

Java Environment for Parallel Realtime Development Platform Independent Software Development for Multicore Systems

Threads & Tasks: Executor Framework

Transcription:

Computer Science 483/580 Concurrent Programming Midterm Exam February 23, 2009 Your name There are 6 pages to this exam printed front and back. Please make sure that you have all the pages now. The exam is designed to take about 50 minutes. This exam is open book and open notes. Cell phones, PDAs, computers, and other electronic devices are not allowed except you may use a laptop computer to refer to an electronic copy of the textbook if you do not have a hardcopy. Honor statement: I have followed the above instructions regarding use of electronic devices while taking this exam. Signature Date 1. Write a Java class called Semaphore that implements the basics of the semaphore abstraction described in section 5.5.3 (pp. 98-99) using Java intrinsic synchronization. In particular you need to implement: a constructor, taking as argument the initial number of permits; the acquire() method and the release() method. You do not need to implement methods that can time out nor show code related to exception handling. I just want to see the essence of the synchronization behavior. 1

2. Joe Java Programmer (JJP) has just learned about threads. He is writing a program that will add up all the space used by the files in a directory and its subdirectories (recursively) and he is excited to think how much faster it will be using threads because of all the parallelism he will achieve. a) In Joe s first attempt, the program enumerates the given, top-level, directory identifying the subdirectories and ordinary files. For each subdirectory a new thread is created that enumerates that subdirectory creating a thread for each of its subdirectories and so forth. Explain why this is a really bad approach to performing this computation. b) Being disappointed with the results of the approach in part a) of the problem, Joe reads Chapter 6 and uses the Executor framework to manage threads in his program, using a fixed thread pool. What factors should Joe consider in choosing the size of the fixed thread pool and how will each of those factors influence his choice? 2

3. Java s intrinsic synchronization relies on data fields in all Objects to support synchronized blocks (and methods) and wait/notify/notifyall. Given what you know about Java intrinsic synchronization, describe the data fields required in every object to support intrinsic synchronization including reentrancy; an unlimited number of threads waiting to enter a synchronized block; an unlimited number of threads waiting for wait(). Don t forget that these fields may themselves be accessed concurrently. Grads: Given the size overhead required in every Object to support intrinsic synchronization, what is your assessment of the design decision to enable every object to participate in intrinsic synchronization? 3

4. The Vector class below is intended to provide a mutable, thread-safe representation of 2-D vectors. public class Vector { private int x, y; public Vector(int x, int y) { this.set(x, y); public Vector(Vector v) { synchronized(v) { this.set(v.x, v.y); public synchronized int[] get() { return new int[] {x, y; public synchronized void set(int x, int y) { this.x = x; this.y = y; public synchronized void add(vector v) { synchronized(v) { this.x += v.x; this.y += v.y; a) The code is subject to deadlock due to the add method. Give an example of client code that could cause a deadlock. b) Suggest at least one way to fix the problem c) The second constructor also acquires two locks. Even so, it is not subject to deadlock. Explain why. 4

5. Joe Java is back and is now concerned that his code will not perform well if it relies on the Java garbage collector. JJP decides to implement his own reference counting scheme for existing class Foo using the RefCountedFooPool class on the next page. You should assume that class TSList is a thread-safe list implementation with threadsafe methods isempty(), add() and remove(). Joe s idea is that he will use the pool to recycle existing object instances whose refcounts have reached 0. Discuss the following: a) are instances of RefCountedFooPool properly constructed? That is, does this escape during construction? Why or why not? b) are instances of RefCountedFoo properly constructed? Why or why not? c) is synchronization used correctly for the refcount field? Why or why not? d) is synchronization used correctly for the operations on the pool object? Why or why not? 5

e) JJP should have in mind an invariant concerning the refcount field of objects contained in the pool list. What would a sensible invariant be? Is this what JJP implemented? Explain. import java.util.*; public final class RefCountedFooPool { private final class RefCountedFoo { public Foo o; private int refcount; public RefCountedFoo(Foo o) { this.refcount = 1; this.o = o; pool.add(this); public synchronized int incrementref() { return ++refcount; public synchronized int decrementref() { --refcount; if (refcount==0) pool.add(this); return refcount; public RefCountedFoo getfrompool() { if (!pool.isempty()) return pool.remove(0); return new RefCountedFoo(new Foo()); final TSList <RefCountedFoo> pool = new ArrayList<RefCountedFoo> (); 6