Concurrency: State Models & Design Patterns

Similar documents
Concurrency: State Models & Design Patterns

Concurrency. State Models and Java Programs. Jeff Magee and Jeff Kramer. Concurrency: introduction 1. Magee/Kramer

CONCURRENT PROGRAMMING - EXAM

Concurrency Control. Synchronization. Brief Preview of Scheduling. Motivating Example. Motivating Example (Cont d) Interleaved Schedules

MultiThreading. Object Orientated Programming in Java. Benjamin Kenwright

Concurrency: State Models & Design Patterns. Q&A Session Week 13

CSE 153 Design of Operating Systems

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

C340 Concurrency: Semaphores and Monitors. Goals

Last Class: Monitors. Real-world Examples

Parallelism Marco Serafini

CSCI 5828: Foundations of Software Engineering

MCS-378 Intraterm Exam 1 Serial #:

CS 153 Design of Operating Systems Winter 2016

Concurrent Programming

Concurrent Programming Synchronisation. CISTER Summer Internship 2017

Lecture 10: Introduction to Semaphores

Taming Dava Threads. Apress ALLEN HOLUB. HLuHB Darmstadt

Deadlock and Monitors. CS439: Principles of Computer Systems February 7, 2018

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

Monitors & Condition Synchronization

Operating Systems: Quiz2 December 15, Class: No. Name:

Synchronization. Announcements. Concurrent Programs. Race Conditions. Race Conditions 11/9/17. Purpose of this lecture. A8 released today, Due: 11/21

27/04/2012. We re going to build Multithreading Application. Objectives. MultiThreading. Multithreading Applications. What are Threads?

SFDV3006 Concurrent Programming

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

Monitors & Condition Synchronization

Comp 204: Computer Systems and Their Implementation. Lecture 9: Deadlock

THE QUEEN S UNIVERSITY OF BELFAST

Lecture 8: September 30

Threads Questions Important Questions

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

The University of Texas at Arlington

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

Models of concurrency & synchronization algorithms

Lecture Topics. Announcements. Today: Concurrency: Mutual Exclusion (Stallings, chapter , 5.7)

CSCI 346 Final Exam Review Materials

Sharing Objects Ch. 3

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

System Software Assignment 8 Deadlocks

Monitors & Condition Synchronization

Lecture 7: Process & Thread Introduction

G52CON: Concepts of Concurrency

Synchronization Lecture 23 Fall 2017

User Space Multithreading. Computer Science, University of Warwick

MultiThreading 07/01/2013. Session objectives. Introduction. Introduction. Advanced Java Programming Course

Advanced Java Programming Course. MultiThreading. By Võ Văn Hải Faculty of Information Technologies Industrial University of Ho Chi Minh City

3C03 Concurrency: Starvation and Deadlocks

FCM 710: Architecture of Secure Operating Systems

Last Class: Synchronization Problems!

Synchronization I. Jo, Heeseung

IT 540 Operating Systems ECE519 Advanced Operating Systems

Monitors & Condition Synchronisation

Threads. Threads The Thread Model (1) CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5

Concurrent Programming. Introduction

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

Object Oriented Programming and Design in Java. Session 18 Instructor: Bert Huang

Concurrency: a crash course


Threads, Synchronization, and Scheduling. Eric Wu

OPERATING SYSTEMS. Prescribed Text Book. Operating System Principles, Seventh Edition. Abraham Silberschatz, Peter Baer Galvin and Greg Gagne

Vulkan: Scaling to Multiple Threads. Kevin sun Lead Developer Support Engineer, APAC PowerVR Graphics

THE UNIVERSITY OF WESTERN AUSTRALIA SAMPLE EXAM QUESTIONS 2007 WITH SOLUTIONS SCHOOL OF COMPUTER SCIENCE CITS3213 CONCURRENT PROGRAMMING (PART II)

Shared Objects & Mutual Exclusion

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

Concurrent Processes Rab Nawaz Jadoon

CS153: Deadlock. Chengyu Song. Slides modified from Harsha Madhyvasta, Nael Abu-Ghazaleh, and Zhiyun Qian

Chapter 2 Processes and Threads

G52CON: Concepts of Concurrency

CSC 1600: Chapter 6. Synchronizing Threads. Semaphores " Review: Multi-Threaded Processes"

Computation Abstractions. Processes vs. Threads. So, What Is a Thread? CMSC 433 Programming Language Technologies and Paradigms Spring 2007

CS 162 Midterm Exam. October 18, This is a closed book examination. You have 60 minutes to answer as many questions

Moore s Law. Computer architect goal Software developer assumption

Last Class: Deadlocks. Today

Threads and Parallelism in Java

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

The University of Texas at Arlington

CS140 Operating Systems and Systems Programming Midterm Exam

CS4411 Intro. to Operating Systems Exam 1 Fall points 9 pages

Homework #3. CS 318/418/618, Fall Handout: 10/09/2017

High Performance Computing Course Notes Shared Memory Parallel Programming

Last Class: CPU Scheduling! Adjusting Priorities in MLFQ!

Algorithmic Verification. Algorithmic Verification. Model checking. Algorithmic verification. The software crisis (and hardware as well)

Concurrent & Distributed Systems Supervision Exercises

CONCURRENCY AND THE ACTOR MODEL

Real-Time Operating Systems M. Course Syllabus, Spring 2013

SYNCHRONIZATION M O D E R N O P E R A T I N G S Y S T E M S R E A D 2. 3 E X C E P T A N D S P R I N G 2018

FCM 710: Architecture of Secure Operating Systems

CS 571 Operating Systems. Midterm Review. Angelos Stavrou, George Mason University

Operating Systems. Thread Synchronization Primitives. Thomas Ropars.

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

PROCESS SYNCHRONIZATION

Assignment-2 (TCS/TIT 503)

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

CS 351 Design of Large Programs Singleton Pattern

Answer the first question and two further questions. i. action prefix ( -> ) [3 marks]

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

CSE 153 Design of Operating Systems

Operating Systems. Operating Systems Sina Meraji U of T

Process Management And Synchronization

Transcription:

Concurrency: State Models & Design Patterns Practical Session Week 02 1 / 13

Exercises 01 Discussion

Exercise 01 - Task 1 a) Do recent central processing units (CPUs) of desktop PCs support concurrency? Why became concurrency for many software applications very important these days? Yes, they do. In todays connected world large-scale data analysis requesting huge compute clusters exploiting massive concurrency became very popular in machine learning or trend prediction. b) What is safety? Give one concrete example of a safety violation. Safety is a property of concurrent programs and it claims that the consistency of resources is ensured, i.e., data cannot be corrupted by concurrent processes. For example, a safety violation occurs when two bank transactions happen at the very same time, and the bank account ends up with the wrong balance.

Exercise 01 - Task 1 c) What is liveness? Give a concrete example of a liveness violation. Liveness is a property of concurrent programs and states that processes are eventually (i.e. guaranteed at some time in the future) able to do useful work. A liveness violation occurs, if someone makes a bank transaction and the transaction never finishes. d) Using the implementation in the slides, can a binary semaphore lead to a deadlock? Can it lead to starvation? Explain with the aid of an example. The binary semaphore cannot lead to a deadlock. However, depending on the implementation, it may or may not lead to starvation. If too many processes access the critical section, an unfair implementation of the semaphore can starve some processes.

Exercise 01 - Task 1 e) Why do we need synchronization mechanisms in concurrent programs? Synchronization is needed to ensure safety and liveness in concurrent programs. f) How do monitors differ from semaphores? Please provide a precise answer. They differ in terms of flexibility, usage, and programming style. Semaphores can allow several concurrent processes to enter the mutex, whereas with monitors it is just one.

Exercise 01 - Task 1 g) How are monitors and message passing similar? And how are they different? Monitors and message passing are similar in the sense that they both encapsulate data and operations. They are different in the sense that monitors rely on shared data and processes need to sync using locks, whereas message passing uses no shared state and messages are used to achieve synchronization.

Exercise 01 - Task 2 x := 1 Thread 1 -> x := x + 7. Thread 2 -> x := x * 5. Considering the previous code, give all possible values of x at the end of the execution of both threads with their corresponding execution traces. r1(x = 1), w1(x = 8), r2(x = 8), w2(x = 40) --> 40 r1(x = 1), r2(x = 1), w1(x = 8), w2(x = 5) --> 5 r1(x = 1), r2(x = 1), w2(x = 5), w1(x = 8) --> 8 r2(x = 1), r1(x = 1), w2(x = 5), w1(x = 8) --> 8 r2(x = 1), r1(x = 1), w1(x = 8), w2(x = 5) --> 5 r2(x = 1), w2(x = 5), r1(x = 5), w1(x = 12) --> 12

Exercise 01 - Task 3 Implement a monitor using semaphores. Use pseudo-code and comment it. The general strategy is to implement a lock based on a binary semaphore and then implement a monitor based on that lock. (...) Finally, keep in mind that this is a rough implementation just to give the idea how we can build a concurrency concept based on another.

Exercises 02 Preview

Exercise 02 - Task 1 Answer the following questions: a) What states can a Java thread be in? b) How can you turn a Java class into a monitor? c) What is the Runnable interface good for? d) Specify an FSP that repeatedly performs hello, but may stop at any time.

Exercise 02 - Task 2 Consider the following Java implementation of a Singleton within a singlethreaded application: public class Singleton { private static Singleton instance = null; } private Singleton() {} public static Singleton getinstance() { if(instance == null) { instance = new Singleton(); } return instance; } a) What happens if the application is multithreaded? b) How to implement a thread-safe singleton in Java? c) Suppose there arrive 1000 requests/second from different threads at this Singleton. Does your implementation introduce a bottleneck? If yes, how can you improve it?

Exercise 02 - Task 3 Download LTSA from http://www.doc.ic.ac.uk/ jnm/book/ltsa/download.html. For each of the following processes shown in Figure 1, provide the Finite State Process (FSP) description of the corresponding Labeled Transition System (LTS) graph. You may verify the FSP descriptions by generating the state machines and using the draw functionality of the tool.

Exercise 02 - Task 4 Consider the full Race5K FSP from the lecture. a) How many states and how many possible traces does it have if the number of steps is 5 (as in the lecture)? b) What is the number of states and traces in the general case (i.e. for n steps)? We assume 2 processes. c) Check your solution using the LTSA tool.