Consider the program fragment below left. Assume that the program containing this fragment executes t1() and t2() on separate threads running on separate.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Operating Systems ECE344 Midterm review Ding Yuan
HW/Study Guide. Synchronization Make sure you understand the HW problems!
Ch 7 B.
D u k e S y s t e m s Time, clocks, and consistency and the JMM Jeff Chase Duke University.
Chapter 6: Process Synchronization
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
1 Semaphores and Monitors CIS450 Winter 2003 Professor Jinhua Guo.
Chapter 6 Process Synchronization: Part 2. Problems with Semaphores Correct use of semaphore operations may not be easy: –Suppose semaphore variable called.
CS444/CS544 Operating Systems Synchronization 2/16/2006 Prof. Searleman
Threading Part 4 CS221 – 4/27/09. The Final Date: 5/7 Time: 6pm Duration: 1hr 50mins Location: EPS 103 Bring: 1 sheet of paper, filled both sides with.
“THREADS CANNOT BE IMPLEMENTED AS A LIBRARY” HANS-J. BOEHM, HP LABS Presented by Seema Saijpaul CS-510.
Avishai Wool lecture Introduction to Systems Programming Lecture 4 Inter-Process / Inter-Thread Communication.
Concurrent Processes Lecture 5. Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and.
CMPT 300: Operating Systems Review THIS REIVEW SHOULD NOT BE USED AS PREDICTORS OF THE ACTUAL QUESTIONS APPEARING ON THE FINAL EXAM.
02/23/2004CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Synchronization in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CS510 Concurrent Systems Class 5 Threads Cannot Be Implemented As a Library.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Synchronization CSCI 444/544 Operating Systems Fall 2008.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Advances in Language Design
What is the output generated by this program? Please assume that each executed print statement completes, e.g., assume that each print is followed by an.
What is the output generated by this program? (Assume that there are no errors or failures.) [30 pts] CPS 310 final exam, 12/12/2014 Your name please:
(a) Alice and Bob are back together. Today Alice wants to send Bob a message that is secret and also authenticated, so that Bob "knows" the message came.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
CHAPTER 2: COMPUTER-SYSTEM STRUCTURES Computer system operation Computer system operation I/O structure I/O structure Storage structure Storage structure.
Cosc 4740 Chapter 6, Part 3 Process Synchronization.
Consider the short (and useless) C program off to the right. Each of the variables {a, b, c} references an integer value that occupies some memory at runtime.
Consider the Java code snippet below. Is it a legal use of Java synchronization? What happens if two threads A and B call get() on an object supporting.
6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
(a) What is the output generated by this program? In fact the output is not uniquely defined, i.e., it is not always the same. So please give three examples.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
Consider the program fragment below left. Assume that the program containing this fragment executes t1() and t2() on separate threads running on separate.
Threaded Programming in Python Adapted from Fundamentals of Python: From First Programs Through Data Structures CPE 401 / 601 Computer Network Systems.
CSE 451: Operating Systems Section 5 Midterm review.
ICS 313: Programming Language Theory Chapter 13: Concurrency.
Processor Architecture
(a) What is the output generated by this program? In fact the output is not uniquely defined, i.e., it is not necessarily the same in each execution. What.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
1 Condition Variables CS 241 Prof. Brighten Godfrey March 16, 2012 University of Illinois.
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
Problems with Semaphores Used for 2 independent purposes –Mutual exclusion –Condition synchronization Hard to get right –Small mistake easily leads to.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
CS533 – Spring Jeanie M. Schwenk Experiences and Processes and Monitors with Mesa What is Mesa? “Mesa is a strongly typed, block structured programming.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Synchronization Emery Berger and Mark Corner University.
Consider the Java code snippet below. Is it a legal use of Java synchronization? What happens if two threads A and B call get() on an object supporting.
CS333 Intro to Operating Systems Jonathan Walpole.
1 Why Threads are a Bad Idea (for most purposes) based on a presentation by John Ousterhout Sun Microsystems Laboratories Threads!
CSCI1600: Embedded and Real Time Software Lecture 17: Concurrent Programming Steven Reiss, Fall 2015.
Introduction to operating systems What is an operating system? An operating system is a program that, from a programmer’s perspective, adds a variety of.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
pThread synchronization
Tutorial 2: Homework 1 and Project 1
Homework Assignment #2 J. H. Wang Oct. 25, 2016.
CS703 – Advanced Operating Systems
Background on the need for Synchronization
Lecture 25 More Synchronized Data and Producer/Consumer Relationship
Process management Information maintained by OS for process management
CSCI1600: Embedded and Real Time Software
CS333 Intro to Operating Systems
Chapter 6: Synchronization Tools
CSCI1600: Embedded and Real Time Software
CSE 451 Section 1/27/2000.
Process/Thread Synchronization (Part 2)
Presentation transcript:

Consider the program fragment below left. Assume that the program containing this fragment executes t1() and t2() on separate threads running on separate cores. They run concurrently as depicted in the timeline below. Assume a modern multicore system with a shared memory and lock() and unlock() primitives. Answer (a), (b), (c) below, noting any additional assumptions you make. Qualifying exam: operating systems, 1/5/2015 Part 1. Consistency int x=0, y=0; t1() { int i, j; i = x; /* R(x) */ x = 1; /* W(x) */ j = y; /* R(y) */ y = 1; /* W(y) */ … } t2() { int i, j; i = y; /* R(y) */ y = 2; /* W(y) */ j = x; /* R(x) */ x = 2; /* W(x) */ … } t1 W(x)=1 t2 R(x)W(y)=1R(y) W(y)=2R(y)W(x)=2R(x) (a)Is there any sequentially consistent execution of t1 and t2 that could yield R(y) = 0 in t1 and R(x) = 0 in t2? Why or why not? The point here is to demonstrate an understanding of sequential consistency. 0?

(b) Annotate the timeline below to show how to use locks to ensure a sequentially consistent execution with respect to the operations on x and y. Illustrate the resulting partial order of events by adding directed arcs between events to indicate Lamport happens-before relationships, and annotating the events with values for logical clocks and vector clocks. Part 1. (Continued) t1 W(x)=1 t2 R(x)W(y)=1R(y) W(y)=2R(y)W(x)=2R(x) (c) Annotate the timeline below to show how to use locks to ensure a serializable execution of t1 and t2 (in the sense of atomic transactions). Illustrate the resulting partial order of events as in (b). t1 W(x)=1 t2 R(x)W(y)=1R(y) W(y)=2R(y)W(x)=2R(x) CPS 510 qualifying exam, 1/5/2015, page 2 of 8

semaphore mutex(0); /* init 0 */ semaphore condition(1); /* init 1 */ acquire() { mutex.p(); } release() { mutex.v(); } wait() { condition.p(); } signal() { condition.v(); } A monitor is a classic abstraction for concurrency control using the four operations on the right. Monitors appear in modern programming languages including Java and C#, and as linked mutexes and condition variables in Modula-2 and pthreads. The pseudo- code on the right is a flawed implementation of monitors using semaphores. (P is down, and V is up). This question asks you to summarize what is wrong with the code. Write a list of four distinct correctness properties that this solution violates even when used correctly. Outline a fix for each one. Feel free to mark the code. Part 2. Concurrency CPS 510 qualifying exam, 1/5/2015, page 3 of 8

Part 3. Threads and scheduling This part asks you to write code to synchronize a standard event/request queue (a thread pool). Any kind of pseudocode is fine as long as its meaning is clear. You may assume standard data structures, e.g., linked lists: don’t write code for those. Threads place event records on the queue using the put method. (E.g., put might be called by a network connection handler.) A pool of worker threads get event records from the queue and a call handler routine to process each event. When a handler completes, the worker calls get again for the next event. The workers sleep if the queue is empty. Note: I am only asking you to code up the put and get methods, and not any thread/code that calls those methods. (a) Implement put and get using monitors (or mutex + condition variable). event queue worker loop Worker thread do: { get next event; invoke handler; loop. } (Sleep if no events.) put handler get put (Event e) { get() returns Event e { }} CPS 510 qualifying exam, 1/5/2015, page 4 of 8 thread

(b) Modify your answer to (a) to reduce average response time. Suppose there are three types of incoming events with different average service demands: the handler for type A events takes one time unit to execute, type B events take 2 units, and type C events take 3 units. You may assume each event record is tagged with exactly one type code (A, B, or C). Your solution should be free from starvation and deadlock. Code is optional: if you can explain your solution without writing code, that is sufficient. Part 3. (Continued) CPS 510 qualifying exam, 1/5/2015, page 5 of 8

Part 4. Performance Suppose I have a service that runs on a server S and receives requests from a network. Each request on S reads a randomly chosen piece of data from a disk attached to S, and also does some computing. On average, a request arriving when S is idle spends T time units computing on the CPU and T time units waiting for data from the disk. Now suppose I redeploy the service on a new server S’. S’ is the same as S, except that the CPU is 20% faster and S’ has two disks, each containing a copy of the data. (a) Sketch the throughput and mean response time of S and S’ as the request arrival rate increases. Sketch the graphs, label the axes, and annotate key features of the graphs. What are the peak throughputs of S and S’ at saturation? Note any other assumptions you need to answer the question. Throughput Mean response time CPS 510 qualifying exam, 1/5/2015, page 6 of 8

Part 4. (Continued) (b) Now suppose I add memory to S’ so that it can cache half of the data stored on the disks. What impact does this change have on the peak throughput? What impact does it have on the utilization of the disks? Again, note any additional assumptions made in your answer. CPS 510 qualifying exam, 1/5/2015, page 7 of 8

CPS 510 qualifying exam, 1/5/2015, page 8 of 8 Part 5. Virtualization What is the purpose of copy-on-write (COW)? Outline a scenario in which a virtual memory system uses COW. List a sequence of events that occurs to trigger a COW operation and to complete the operation. Outline (or sketch) the data structures that the OS needs to recognize a triggering scenario and to complete the operation.