Comp2310 & Comp6310 Concurrent and Distributed Systems

Similar documents
Comp2310 & Comp6310 Systems, Networks and Concurrency

Comp2310 & Comp6310 Systems, Networks and Concurrency

Comp2310 & Comp6310 Systems, Networks and Concurrency

THE AUSTRALIAN NATIONAL UNIVERSITY Mid-semester Quiz, Second Semester COMP2310 (Concurrent and Distributed Systems)

THE AUSTRALIAN NATIONAL UNIVERSITY Practice Final Examination, October 2012

Concurrent Processes Rab Nawaz Jadoon

Concurrent & Distributed Systems Supervision Exercises

Synchronization COMPSCI 386

CSE 153 Design of Operating Systems

A Sophomoric Introduction to Shared-Memory Parallelism and Concurrency Lecture 5 Programming with Locks and Critical Sections

Transforming Ada Serving Tasks Into Protected Objects

CSE332: Data Abstractions Lecture 19: Mutual Exclusion and Locking

COMP 346 Winter 2019 Programming Assignment 2

1995 Paper 10 Question 7

ENGR 3950U / CSCI 3020U UOIT, Fall 2012 Quiz on Process Synchronization SOLUTIONS

CSE332: Data Abstractions Lecture 23: Programming with Locks and Critical Sections. Tyler Robison Summer 2010

CSE 307: Principles of Programming Languages

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

Notes on the Exam. Question 1. Today. Comp 104:Operating Systems Concepts 11/05/2015. Revision Lectures (separate questions and answers)

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

Remaining Contemplation Questions

1 Process Coordination

Comp 204: Computer Systems and Their Implementation. Lecture 25a: Revision Lectures (separate questions and answers)

Lecture 5: Declarative Programming. The Declarative Kernel Language Machine. September 12th, 2011

main read Identical static threads Dynamic threads with Concurrent and

CS4215 Programming Language Implementation

Enforcing Mutual Exclusion Using Monitors

COMMUNICATING TASKS. Week 6 Laboratory for Concurrent and Distributed Systems Uwe R. Zimmer based on material by Alistair Rendell

Sharing Objects Ch. 3

CS171 Midterm Exam. October 29, Name:

Last Class: Synchronization Problems!

A simple example... Introduction to Ada95. Literals. Identifiers

Please note that if you write the mid term in pencil, you will not be allowed to submit a remark request.

IT 4043 Data Structures and Algorithms. Budditha Hettige Department of Computer Science

INSTITUTE OF AERONAUTICAL ENGINEERING

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

The Deadlock Problem (1)

3/25/14. Lecture 25: Concurrency. + Today. n Reading. n P&C Section 6. n Objectives. n Concurrency

COMP 2320 Operating Systems 1st Semester, Mid-term Examination

Exercises and Labs. Part I. Exercises

September 10,

G52CON: Concepts of Concurrency

Fall 2015 COMP Operating Systems. Lab 06

CSE 120 Principles of Operating Systems Spring 2016

OPERATING SYSTEMS ECSE 427/COMP SECTION 01 WEDNESDAY, DECEMBER 7, 2016, 9:00 AM

Chapter 5 Asynchronous Concurrent Execution

Ch. 7: Control Structures

Ada 2005 An introduction for TTK4145

Chapter 2 Processes and Threads

Stacks and Queues

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems

Chapter 7: Deadlocks. Operating System Concepts with Java 8 th Edition

Introduction & Languages

Midterm - Winter SE 350

Abstract Data Types Documentation

Operating Systems ECE344

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

COMP 300E Operating Systems Fall Semester 2011 Midterm Examination SAMPLE. Name: Student ID:

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2013

Name CPTR246 Spring '17 (100 total points) Exam 3

+ Today. Lecture 26: Concurrency 3/31/14. n Reading. n Objectives. n Announcements. n P&C Section 7. n Race conditions.

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

Modal Logic: Implications for Design of a Language for Distributed Computation p.1/53

Problem Set 5 Solutions

TDDD56 Multicore and GPU computing Lab 2: Non-blocking data structures

Opera&ng Systems ECE344

Process Synchronisation (contd.) Deadlock. Operating Systems. Spring CS5212

Deadlock Risk Management

Introduction & Languages

Programming in Parallel COMP755

CMSC 714 Lecture 14 Lamport Clocks and Eraser

Process Management And Synchronization

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES

Lab # 2. Sequential Statements

VALLIAMMAI ENGINEERING COLLEGE

Principles of Software Construction: Concurrency, Part 2

G52CON: Concepts of Concurrency

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

Chapter 6: Process Synchronization

Inheritance. Transitivity

Exam Concurrent and Real-Time Programming

Concurrent and Real-Time Programming in Java

Data Structures G5029

SCOOP A contract-based concurrent object-oriented programming model

Today s lecture. CS 314 fall 01 C++ 1, page 1

Concurrency: Deadlock and Starvation. Chapter 6

Coordination and Agreement

Concurrent and Distributed Systems Introduction

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

Shared Memory Programming Models I

Abstract Data Types! Documentation!

CMPSCI 187: Programming With Data Structures. Lecture #11: Implementing Stacks With Arrays David Mix Barrington 28 September 2012

Midterm - Winter SE 350

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement

Lecture 8: September 30

PROCESSES AND THREADS

ADTs Stack and Queue. Outline

Question 1. Notes on the Exam. Today. Comp 104: Operating Systems Concepts 11/05/2015. Revision Lectures

CSCI312 Principles of Programming Languages!

Transcription:

The Australian National University Final Examination November 2015 Comp2310 & Comp6310 Concurrent and Distributed Systems Study period: 15 minutes Writing time: 3 hours (after study period) Total marks: 100 Permitted materials: None Questions are not equally weighted sizes of answer boxes do not necessarily relate to the number of marks given for this question. All your answers must be written in the boxes provided in this booklet. You will be provided with scrap paper for working, but only those answers written in this booklet will be marked. Do not remove this booklet from the examination room. There is additional space at the end of the booklet in case the boxes provided are insufficient. Label any answer you write at the end of the booklet with the number of the question it refers to. Greater marks will be awarded for answers that are simple, short and concrete than for answers of a sketchy and rambling nature. Marks will be lost for giving information that is irrelevant to a question. Student number: The following are for use by the examiners Q1 mark Q2 mark Q3 mark Q4 mark Q5 mark Q6 mark Total mark

1. [16 marks] General Concurrency (a) [3 marks] Give three examples of hardware components that support concurrency. (b) [5 marks] What will be the output (or the possible outputs) of the following concurrent program? Give precise reasons for your answer. If you need to make assumptions about the underlying operating system, runtime environment or hardware then state those assumptions as well. with Ada.Text_IO; use Ada.Text_IO; procedure x_value is x : Positive := 1; task One; task body One is x := x + x; end One; task Two; task body Two is x := x + x; end Two; Put (Positive Image (x)); end x_value; Comp2310 & Comp6310 Final Exam 2015 Page 2 of 22

(c) [3 marks] How does a block of Dijktra s guarded commands differ from a switch statement as you find it in Java or C? Name at least two essential differences. (d) [3 marks] How does a forall statement (as in Chapel) differ from a for statement as you find it in Java or C? Be as precise as you can. (e) [2 marks] If you define a boolean expression which is true when all your concurrent processes are terminated could such an expression be regarded as a safety or a liveness property? Do all concurrent programs have to fulfil such a termination condition? Give precise reasons for both answers. Comp2310 & Comp6310 Final Exam 2015 Page 3 of 22

2. [14 marks] Synchronization and Communication Student number:... (a) [5 marks] Can synchronous message passing systems emulate asynchronous message passing? Can asynchronous message passing systems emulate synchronous message passing? For both questions provide either a reason why this is not possible or a diagram which is depicting how it could work. If it is only possible under certain assumptions then also state those assumptions. Comp2310 & Comp6310 Final Exam 2015 Page 4 of 22

(b) [3 marks] Define a general semaphore (as offered by an operating system) precisely. Only the defining characteristics are asked for here not the additional convenience functions which might be offered as well by an operating system. (c) [2 marks] Can you program a semaphore if your programming language does not provide one? If you need to make assumptions to answer this question then explain them here as well. (d) [4 marks] Which problematic issues with semaphores are resolved by monitors? Which issues are not? Explain at least one resolved and one unresolved issue. Comp2310 & Comp6310 Final Exam 2015 Page 5 of 22

3. [9 marks] Selective Concurrency (a) [9 marks] Read the following Ada code carefully. The tasks and the calling code section are syntactically correct and will compile without warnings. task Selector is entry Start; entry E1; entry E2; end Selector; with three different versions for its body (all delay values are in seconds): Version 1: Version 2: Version 3: task body Selector is accept Start; for i in 1.. 2 loop select accept E1 do delay 2.0; Put ( X ); end E1; or accept E2; delay 2.0; Put ( Y ); or terminate; end select; delay 1.0; Put ( Z ); end loop; end Selector; task body Selector is accept Start; for i in 1.. 2 loop select accept E1; delay 2.0; Put ( X ); or delay 2.0; accept E2; Put ( Y ); exit; end select; delay 1.0; Put ( Z ); end loop; end Selector; task body Selector is accept Start; for i in 1.. 2 loop select accept E1 do delay 2.0; Put ( X ); end E1; else accept E2; delay 2.0; Put ( Y ); exit; end select; delay 1.0; Put ( Z ); end loop; end Selector; Called by this code section: Selector.Start; Put ( A ); delay 1.0; select Selector.E1; Put ( B ); else Put ( C ); end select; delay 1.0; Selector.E2; delay 1.0; Put ( D ); (i) [9 marks] Add the outputs for all three versions to the time lines below (assume that Start is called at time zero): Version 1: Version 2: Version 3: 0 1 2 3 4 5 6 7 8 9 [seconds] Comp2310 & Comp6310 Final Exam 2015 Page 6 of 22

4. [17 marks] Safety and Liveness (a) [17 marks] Read the following Ada package carefully. The package is syntactically correct and will compile without warnings. See explanation and questions after the program code. generic type Element is private; Size : Positive; package Stack_with_Semaphores_Generic is type Stack_Type is limited private; procedure Push (Item : Element; Stack : in out Stack_Type); procedure Pop (Item : out Element; Stack : in out Stack_Type); function Is_Empty (Stack : in out Stack_Type) return Boolean; function Is_Full (Stack : in out Stack_Type) return Boolean; private protected type Semaphore (Initial : Natural := 0) is entry Wait; procedure Signal; private Value : Natural := Initial; end Semaphore; type List is array (1.. Size) of Element; type Stack_Type is record Top : Natural := 0; Elements : List; Write_Lock : Semaphore (1); Read_Lock : Semaphore (1); Is_Empty : Semaphore (0); Is_Full : Semaphore (Size); Readers : Natural := 0; end record; end Stack_with_Semaphores_Generic; package body Stack_with_Semaphores_Generic is protected body Semaphore is entry Wait when Value > 0 is Value := Natural Pred (Value); end Wait; procedure Signal is Value := Natural Succ (Value); end Signal; end Semaphore; (continued on next page) Comp2310 & Comp6310 Final Exam 2015 Page 7 of 22

procedure Push (Item : Element; Stack : in out Stack_Type) is Stack.Write_Lock.Wait; Stack.Is_Full.Wait; Stack.Top := Positive Succ (Stack.Top); Stack.Elements (Stack.Top) := Item; Stack.Is_Empty.Signal; Stack.Write_Lock.Signal; end Push; procedure Pop (Item : out Element; Stack : in out Stack_Type) is Stack.Write_Lock.Wait; Stack.Is_Empty.Wait; Item := Stack.Elements (Stack.Top); Stack.Top := Positive Pred (Stack.Top); Stack.Is_Full.Signal; Stack.Write_Lock.Signal; end Pop; procedure Start_Read (Stack : in out Stack_Type) is Stack.Read_Lock.Wait; if Stack.Readers = 0 then Stack.Write_Lock.Wait; end if; Stack.Readers := Natural Succ (Stack.Readers); Stack.Read_Lock.Signal; end Start_Read; procedure Stop_Read (Stack : in out Stack_Type) is Stack.Read_Lock.Wait; Stack.Readers := Natural Pred (Stack.Readers); if Stack.Readers = 0 then Stack.Write_Lock.Signal; end if; Stack.Read_Lock.Signal; end Stop_Read; function Is_Empty (Stack : in out Stack_Type) return Boolean is Start_Read (Stack); Stop_Read (Stack); return Stack.Top < Stack.Elements First; end Is_Empty; function Is_Full (Stack : in out Stack_Type) return Boolean is Start_Read (Stack); Stop_Read (Stack); return Stack.Top = Stack.Elements Last; end Is_Full; end Stack_with_Semaphores_Generic; Comp2310 & Comp6310 Final Exam 2015 Page 8 of 22

The package is intended to provide concurrency-safe access to a stack where the operations Push and Pop are mutually exclusive to all other operations and the side-effect free (with respect to the stack data) operations Is_Empty and Is_Full can be executed by multiple tasks concurrently (unless Push or Pop are currently executing). (i) [3 marks] Explain the usage and the meaning of the initialization values of the individual semaphores. What minimum and maximum values can each Semaphore reach? (ii) [3 marks] Can any data be accessed in an unsynchronized way? If so, point out where this can happen and how you would prevent this. (iii) [3 marks] Are there any possibilities for deadlocks in the operations Push, Pop, Is_Empty or Is_Full? If so, point out where this could happen and how you would prevent this. Comp2310 & Comp6310 Final Exam 2015 Page 9 of 22

(iv) [8 marks] Write a package with the same functionality, which is deadlock-free, synchronizes all access to shared data, distinguishes read and write access and is less than half the length of the given package. Safety and liveness properties of your version should be obvious or easy to check. Comp2310 & Comp6310 Final Exam 2015 Page 10 of 22

5. [19 marks] Data Parallelism (a) [8 marks] Read this syntactically correct Chapel expression and then proceed to the questions below: reduce (Vector_1!= Vector_2) where you should assume the declarations: const Index = {1.. 100000000}; var Vector_1, Vector_2 : [Index] real; (i) [1 mark] What is the type of this expression? (ii) [5 marks] Enumerate and explain the data parallel operations which are implemented by this Chapel expression. (iii) [2 marks] How many concurrent entities (tasks, processes, threads or alike) are created with this expression? Give reasons for your answer. Comp2310 & Comp6310 Final Exam 2015 Page 11 of 22

(b) [11 marks] Blocking operations are commonly kept at a minimum in high performance applications. (i) [6 marks] Explain how a shared queue data structure can be implemented such that some/all interferences between readers and writers of such a queue can be avoided. Briefly outline a possible implementation. Comp2310 & Comp6310 Final Exam 2015 Page 12 of 22

(ii) [5 marks] Can blocking/synchronization operations be completely avoided in some concurrent programs? Give an example if you think this is the case and explain which sorts of applications could be implemented without any blocks/synchronizations? If you think that this is not the case then explain why blocking/synchronization is always necessary. Comp2310 & Comp6310 Final Exam 2015 Page 13 of 22

6. [25 marks] Distributed Systems (a) [5 marks] What can you conclude about the events a and b (including whether they happened on the same or on different processors) if the relations between the logical times C^ah and C^bh associated with these events are: (i) [1 mark] C^ah! Cb ^ h (ii) [1 mark] C^ah= Cb ^ h (iii) [1 mark] C^ah> Cb ^ h (iv) [2 marks] Is it true that if Ca ^ h< Cb ^ h then there always exists an event c, such that: C^ah< C^ch< C^bh? Will your answer change if you measure time in calendar (or real ) time instead of logical time? Give precise reasons for your answers. Comp2310 & Comp6310 Final Exam 2015 Page 14 of 22

(b) [20 marks] Read the following Ada program carefully. The program is syntactically correct and will compile without warnings. See questions on the following pages. This first page contains only definitions for the sequential part of the program and you can ignore it when analyzing the concurrent aspects. with Ada.Containers.Vectors; use Ada.Containers; with Ada.Text_IO; use Ada.Text_IO; procedure Mini is No_Of_Stages : constant Positive := 8; No_Of_Elements : constant Positive := 2 ** No_Of_Stages; subtype Element is Natural; type Element_Array is array (Natural range <>) of Element; function Is_Sorted (D : Element_Array) return Boolean is (for all i in D First.. D Last - 1 => D (i) <= D (i + 1)); function Is_Permutation (Field_A, Field_B : Element_Array) return Boolean is package Element_Vectors is new Vectors (Positive, Element); use Element_Vectors; package Sorting is new Generic_Sorting; use Sorting; Vector_A, Vector_B : Vector := Empty_Vector; for A of Field_A loop Append (Vector_A, A); end loop; for B of Field_B loop Append (Vector_B, B); end loop; Sort (Vector_A); Sort (Vector_B); return Vector_A = Vector_B; end Is_Permutation; function Merge (A, B : Element_Array) return Element_Array is (if A Length = 0 then B elsif B Length = 0 then A elsif A (A First) < B (B First) then A (A First) & Merge (A (Natural Succ (A First).. A Last), B) else B (B First) & Merge (A, B (Natural Succ (B First).. B Last))) with Pre => Is_Sorted (A) and then Is_Sorted (B), Post => Is_Sorted (Merge Result) and then Is_Permutation (Merge Result, A & B); subtype Stage_Range is Natural range 0.. No_Of_Stages - 1; (continued on next page) Comp2310 & Comp6310 Final Exam 2015 Page 15 of 22

task type Stage is entry Hand_over_Id (Set_Id : Stage_Range); entry Feed (E : Element); end Stage; Stages : array (Stage_Range) of Stage; task body Stage is Id : Stage_Range := Stage_Range Invalid_Value; accept Hand_over_Id (Set_Id : Stage_Range) do Id := Set_Id; end Hand_over_Id; declare type Channels is (Left, Right); Feeds : array (Channels) of Element_Array (1.. 2 ** Natural (Id)); loop for Ch in Channels loop for F of Feeds (Ch) loop select accept Feed (E : Element) do F := E; end Feed; or terminate; end select; end loop; end loop; declare Merged_Feed : constant Element_Array := Merge (Feeds (Left), Feeds (Right)); if Id < Stage_Range Last then for M of Merged_Feed loop Stages (Id + 1).Feed (M); end loop; else Put_Line ( Pipeline output is & (if Is_Sorted (Merged_Feed) then sorted else not sorted )); end if; end; end loop; end; end Stage; for Id in Stage_Range loop Stages (Id).Hand_over_Id (Id); end loop; for E in reverse 1.. No_Of_Elements loop Stages (Stages First).Feed (E); end loop; end Mini; Comp2310 & Comp6310 Final Exam 2015 Page 16 of 22

(i) [2 marks] How many concurrent entities are implemented with this program? What are they? (ii) [4 marks] What are the dependencies (shared data, synchronisation, etc.) between the concurrent entities and how do they interact? Could these concurrent entities be physically distributed? Give precise reasons. (iii) [2 marks] How many stages do you need to process n elements with this algorithm (i.e. by feeding n elements into the first stage)? (iv) [2 marks] When will the last stage receive its first data and when does it start to process (merge) data? Express this in global time, where the time unit is a single message. Comp2310 & Comp6310 Final Exam 2015 Page 17 of 22

(v) [4 marks] What is the time complexity for this algorithm (assuming that all stages are running on physically parallel hardware)? (vi) [4 marks] What would be the total computational complexity (calculate this by adding up the computational complexities for all nodes)? (vii) [2 marks] Will this program terminate? Give precise reasons. Comp2310 & Comp6310 Final Exam 2015 Page 18 of 22

continuation of answer to question part continuation of answer to question part Comp2310 & Comp6310 Final Exam 2015 Page 19 of 22

continuation of answer to question part continuation of answer to question part Comp2310 & Comp6310 Final Exam 2015 Page 20 of 22

continuation of answer to question part continuation of answer to question part Comp2310 & Comp6310 Final Exam 2015 Page 21 of 22

continuation of answer to question part continuation of answer to question part Comp2310 & Comp6310 Final Exam 2015 Page 22 of 22