DUBLIN CITY UNIVERSITY

Similar documents
Concurrency in Object Oriented

G52CON: Concepts of Concurrency

JFokus Finding And Solving Java Deadlocks

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

Process Synchronization

Resource management. Real-Time Systems. Resource management. Resource management

Synchronization I. Jo, Heeseung

Chapter 6: Process Synchronization

Java 8 From Smile To Tears: Emotional Stampedlock

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem?

Chapter 6: Synchronization. Operating System Concepts 8 th Edition,

Process Synchronization. Mehdi Kargahi School of ECE University of Tehran Spring 2008

Synchronization COMPSCI 386

Concurrency in Object Oriented Programs 3. Object-Oriented Software Development COMP4001 CSE UNSW Sydney Lecturer: John Potter

The Dining Philosophers Problem CMSC 330: Organization of Programming Languages

Real-Time Systems. Lecture #4. Professor Jan Jonsson. Department of Computer Science and Engineering Chalmers University of Technology

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

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems

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

JAVA EXAMPLES - SOLVING DEADLOCK

Process Synchronization

Process Synchronization: Semaphores. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

Deadlock Victim && && && && by Dr Heinz Kabutz The Java Specialists Newsletter

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

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

Synchronization I. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Process Synchronization

Summary Semaphores. Passing the Baton any await statement. Synchronisation code not linked to the data

Dept. of CSE, York Univ. 1

Chapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition

CS370 Operating Systems

Lecture 3: Intro to Concurrent Processing using Semaphores

Need for synchronization: If threads comprise parts of our software systems, then they must communicate.

Last Class: Synchronization Problems. Need to hold multiple resources to perform task. CS377: Operating Systems. Real-world Examples

Concurrency in Java Prof. Stephen A. Edwards

CS 455: INTRODUCTION TO DISTRIBUTED SYSTEMS [THREADS] Frequently asked questions from the previous class survey

CHAPTER 6: PROCESS SYNCHRONIZATION

Interprocess Communication By: Kaushik Vaghani

CS370 Operating Systems

Chapter 7: Process Synchronization!

G52CON: Concepts of Concurrency

Only one thread can own a specific monitor

1) Discuss the mutual exclusion mechanism that you choose as implemented in the chosen language and the associated basic syntax

Dr. D. M. Akbar Hussain DE5 Department of Electronic Systems

Lecture. DM510 - Operating Systems, Weekly Notes, Week 11/12, 2018

From Smile To Tears: Emotional StampedLock

Lesson 6: Process Synchronization

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs

Background. The Critical-Section Problem Synchronisation Hardware Inefficient Spinning Semaphores Semaphore Examples Scheduling.

PROCESS SYNCHRONIZATION

Two hours. Question ONE is COMPULSORY UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Friday 25th January 2013 Time: 14:00-16:00

Chapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6.

IV. Process Synchronisation

CMSC 132: Object-Oriented Programming II. Threads in Java

Chapter 6: Process Synchronization

Introduction to OS Synchronization MOS 2.3

COMP31212: Concurrency A Review of Java Concurrency. Giles Reger

Concurrency: Mutual Exclusion and Synchronization. Concurrency

CS Mid term Exam Maximum points 100; Maximum time allowed: 75 minutes

Threads and Java Memory Model

Enforcing Mutual Exclusion Using Monitors

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

Chapter 5 Concurrency: Mutual Exclusion. and. Synchronization. Operating Systems: Internals. and. Design Principles

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

Concurrency: Mutual Exclusion and Synchronization

Concept of a process

Chapters 5 and 6 Concurrency

sample exam Concurrent Programming tda383/dit390 Sample exam March 2016 Time:?? Place: Johanneberg

MCS-378 Intraterm Exam 1 Serial #:

Week 7. Concurrent Programming: Thread Synchronization. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Last Class: Synchronization Problems!

Synchronization Principles

CONCURRENT PROGRAMMING - EXAM

G Programming Languages Spring 2010 Lecture 13. Robert Grimm, New York University

Concurrency: Mutual Exclusion and

re-exam Concurrent Programming tda383/dit390 Date: Time: 14:00 18:00 Place: Maskinhuset (M)

Comp 310 Computer Systems and Organization

Question Points Score Total 100

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Hank Levy 412 Sieg Hall

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

CSE332: Data Abstractions Lecture 19: Mutual Exclusion and Locking

SFDV3006 Concurrent Programming

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

Module 6: Process Synchronization. Operating System Concepts with Java 8 th Edition

Chapter 6: Process Synchronization. Operating System Concepts 9 th Edit9on

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

Homework Assignment #5

! Why is synchronization needed? ! Synchronization Language/Definitions: ! How are locks implemented? Maria Hybinette, UGA

The New Java Technology Memory Model

Prof. Hui Jiang Dept of Computer Science and Engineering York University

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

Java ReentrantLock (Part 1)

G52CON: Concepts of Concurrency

CMSC 330: Organization of Programming Languages

Chair of Software Engineering. Java and C# in depth. Carlo A. Furia, Marco Piccioni, Bertrand Meyer. Java: concurrency

EECE.4810/EECE.5730: Operating Systems Spring 2017 Homework 2 Solution

BSc ( Hons) Computer Science with Network Security. Examinations for / Semester 2

Chapter 32 Multithreading and Parallel Programming

COMPSCI 230 Threading Week8. Figure 1 Thread status diagram [

COMP 322: Fundamentals of Parallel Programming

Transcription:

DUBLIN CITY UNIVERSITY SEMESTER ONE RESIT EXAMINATIONS 2012 MODULE TITLE: MODULE CODE: COURSE: Concurrent Programming CA463/CA463D BSc. in Computer Applications (Software Engineering Stream), Study Abroad YEAR: 4/X EXAMINERS: TIME ALLOWED: INSTRUCTIONS: Dr. J. Power Dr. F. Bannister Dr. Martin Crane Ext: 8974 2 Hours Please answer any 3 questions: Requirements for this paper Please tick (X) as appropriate Log Table Graph Paper Attached Answer Sheet Statistical Tables Floppy Disk Actuarial Tables THE USE OF PROGRAMMABLE OR TEXT STORING CALCULATORS IS EXPRESSLY FORBIDDEN Please note that where a candidate answers more than the required number of questions, the examiner will mark all questions attempted and then select the highest scoring ones. PLEASE DO NOT TURN OVER THIS PAGE UNTIL YOU ARE INSTRUCTED TO DO SO Module Code: CA463 Page 1 of 7

Question 1 [Total marks: 33] 1(a) [12 marks] Define Dekker s Algorithm in words and implement it in SR for two processors. Explain clearly all parts of the code. 1(b) Peterson s algorithm is a variation on Dekker s algorithm whereby each processor uses two variables, flag and turn. A flag value of 1 indicates that the process wants to enter the critical section. The variable turn holds the ID of the process whose turn it is. Entrance to the critical section is granted for process P0 if P1 does not want to enter its critical section or if P1 has given priority to P0 by setting turn to 0. [11 marks] (i) Implement Peterson s algorithm in Java and briefly compare it with Dekker s algorithm. (ii) Show that, in Peterson s algorithm in (i), (a) Mutual Exclusion is satisfied and (b) No Starvation occurs. --[End of Question 1]-- Question 2 [Total marks: 33] 2(a) Show, using SR code, how semaphores may be used to implement monitors and how monitors may be used to implement semaphores. 2(b) [11 marks] Write code in Java to implement a Semaphore class. Your implementation should give a default constructor, a constructor which initialises with value i, a release method (for the P operation) and an acquire method (for the V operation). 2(c) [12 marks] Using the Semaphore class in (b) above, implement the Bounded Buffer Class in Java. The methods void deposit(object value) and Object fetch() should be implemented. --[End of Question 2] Module Code: CA463 Page 2 of 7

Question 3 [Total marks: 33] 3(a) [23 marks] Write code for the Reader-Preference Solution to the Readers-Writers Problem in SR. Explain clearly all parts of the code. Explain briefly (without code) the method of Passing the Baton. What mechanisms does SR provide that make the implementation of Passing the Baton possible? 3(b) Implement in SR and describe fully Ballhausen s solution to the Readers-Writers Problem. Discuss the efficiency of this solution vis-à-vis the Readers-Preference solution in part (a) above. --[End of Question 3] Module Code: CA463 Page 3 of 7

Question 4 [Total marks: 33] 4(a) [9 marks] Explain the difference between Low Level Concurrency Objects and High Level Concurrency Objects in Java. Why would you use the latter rather than the former? 4(b) As part of the java.util.concurrent package what are Lock objects and how do they differ from intrinsic locks? What are ReentrantLocks and in what situations would one use them over synchronized blocks of code? 4(c) [14 marks] For the code given in Figure Q4, [6 marks] (i) What is the meaning of the lock.trylock() method? Explain clearly what is happening at points A, B. What will happen if either/both statements fail? [2 marks] (ii) Explain clearly what is meant by the Code at point C. [6 marks] (iii) Explain clearly what is meant by the Code at point D, identifying the possible problem that is being avoided. Module Code: CA463 Page 4 of 7

Figure Q4 import java.util.*; import java.util.concurrent.*; import java.util.concurrent.locks.*; import static java.util.concurrent.timeunit.nanoseconds; public class BankTransfer { private static Random rnd = new Random(); public boolean transfermoney(account fromacct, Account toacct, DollarAmount amount, long timeout, TimeUnit unit) throws InsufficientFundsException, InterruptedException { long fixeddelay = getfixeddelaycomponentnanos(timeout, unit); long randmod = getrandomdelaymodulusnanos(timeout, unit); long stoptime = System.nanoTime() + unit.tonanos(timeout); D A while (true) { if (fromacct.lock.trylock()) { try { B C if (toacct.lock.trylock()) { try { if (fromacct.getbalance().compareto(amount) < 0) throw new InsufficientFundsException(); else { fromacct.debit(amount); toacct.credit(amount); return true; finally { toacct.lock.unlock(); finally { fromacct.lock.unlock(); if (System.nanoTime() < stoptime) return false; NANOSECONDS.sleep(fixedDelay + rnd.nextlong() % randmod); private static final int DELAY_FIXED = 1; private static final int DELAY_RANDOM = 2; static long getfixeddelaycomponentnanos(long timeout, TimeUnit unit) { return DELAY_FIXED; static long getrandomdelaymodulusnanos(long timeout, TimeUnit unit) { return DELAY_RANDOM; static class DollarAmount implements Comparable<DollarAmount> { public int compareto(dollaramount other) { return 0; DollarAmount(int dollars) { Module Code: CA463 Page 5 of 7

class Account { public Lock lock; void debit(dollaramount d) { void credit(dollaramount d) { DollarAmount getbalance() { return null; class InsufficientFundsException extends Exception { --[End of Question 4] Module Code: CA463 Page 6 of 7

Question 5 [Total marks: 33] 5(a) Sketch Cassavant and Kuhl s taxonomy of load balancing algorithms. Define clearly the heading for each section. State clearly the difference between: 1. Algorithms with One-time Assignment and Dynamic Reassignment. 2. Adaptive and non-adaptive Algorithms. 5(b) [12 marks] Describe Coffman s load balancing algorithm. How would you classify this algorithm? What assumptions is it based on? 5(c) [11 marks] Use Coffman s algorithm to schedule the task graph in Figure Q5 on to a four processor system. Figure Q5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 --[End of Question 5] Module Code: CA463 Page 7 of 7