CS 450 Exam 2 Mon. 11/7/2016

Similar documents
CS 450 Exam 2 Mon. 4/11/2016

Concurrency: Locks. Announcements

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Concurrency: Mutual Exclusion (Locks)

CS 351 Exam 3 Mon. 5/11/2015

This exam paper contains 8 questions (12 pages) Total 100 points. Please put your official name and NOT your assumed name. First Name: Last Name:

CS4961 Parallel Programming. Lecture 12: Advanced Synchronization (Pthreads) 10/4/11. Administrative. Mary Hall October 4, 2011

CMPSCI 377: Operating Systems Exam 1: Processes, Threads, CPU Scheduling and Synchronization. October 9, 2002

Midterm Exam Solutions and Grading Guidelines March 3, 1999 CS162 Operating Systems

CS 167 Midterm Exam. Two Hours; Closed Book; Please Use a Black Pen March 23, 2017

Threads and Too Much Milk! CS439: Principles of Computer Systems February 6, 2019

CS 537 Lecture 11 Locks

Student Name: University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Science

CS 351 Exam 3, Fall 2011

Midterm Exam March 13, 2013 CS162 Operating Systems

Threads and Too Much Milk! CS439: Principles of Computer Systems January 31, 2018

CS 351 Exam 3, Fall 2013

CMSC421: Principles of Operating Systems

CS 351 Exam 1, Fall 2010

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

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

Sharing Objects Ch. 3

CS 3723 Operating Systems: Final Review

Midterm Exam Solutions March 7, 2001 CS162 Operating Systems

1. Introduction. 2. Project Submission and Deliverables

CPS 110 Midterm. Spring 2011

CS 3723 Operating Systems: Final Review

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

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

Midterm Exam March 7, 2001 CS162 Operating Systems

Spring 2001 Midterm Exam, Anthony D. Joseph

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

CS 4410 Operating Systems. Review 1. Summer 2016 Cornell University

Operating systems and concurrency (B08)

CS 140 Midterm Examination Winter Quarter, 2012

Synchronization. CS61, Lecture 18. Prof. Stephen Chong November 3, 2011

Midterm I October 12 th, 2005 CS162: Operating Systems and Systems Programming

Synchronising Threads

Condition Variables CS 241. Prof. Brighten Godfrey. March 16, University of Illinois

CPS 310 midterm exam #1, 2/19/2016

CPS 310 second midterm exam, 11/14/2014

Stanford University Computer Science Department CS 140 Midterm Exam Dawson Engler Winter 1999

Suggested Solutions (Midterm Exam October 27, 2005)

The Real Time Thing. What the hack is real time and what to do with it. 22C3 30. December Erwin Erkinger e.at

Process Synchronization and Communication

CSC369H1 S2016 Midterm Test Instructor: Bogdan Simion. Duration 50 minutes Aids allowed: none. Student number:

In class we examined the need for concurrent execution paths like a consumer and a producer to synchronize their access to a shared ring buffer.

CS 115 Exam 1, Fall 2015 Thu. 09/24/2015

There are 8 total numbered pages, 6 Questions. You have 60 minutes. Budget your time carefully!

High Performance Computing Course Notes Shared Memory Parallel Programming

Thread Synchronization: Foundations. Properties. Safety properties. Edsger s perspective. Nothing bad happens

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

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators)

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Unix System Programming - Chapter 2, part a

Midterm Exam March 3, 1999 CS162 Operating Systems

CS140 Operating Systems and Systems Programming Midterm Exam

CMSC 433 Section 0101 Fall 2012 Midterm Exam #1

CPS 310 second midterm exam, 11/6/2013

CS-537: Midterm Exam (Spring 2001)

CS 160: Interactive Programming

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring 2004

CPSC 261 Midterm 2 Thursday March 17 th, 2016

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

MCS-378 Intraterm Exam 1 Serial #:

Last Class: Deadlocks. Today

Lecture 9: Midterm Review

CS510 Operating System Foundations. Jonathan Walpole

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

Overview. CMSC 330: Organization of Programming Languages. Concurrency. Multiprocessors. Processes vs. Threads. Computation Abstractions

Introduction to Locks. Intrinsic Locks

CPS 110 Final Exam. Spring 2011

Operating Systems (234123) Spring (Homework 3 Wet) Homework 3 Wet

CSE 131 Introduction to Computer Science Fall Exam II

Advance Operating Systems (CS202) Locks Discussion

Operating systems and concurrency (B10)

Threads CS1372. Lecture 13. CS1372 Threads Fall / 10

CS 318 Principles of Operating Systems

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Processes and threads

Midterm I October 18 th, 2010 CS162: Operating Systems and Systems Programming

Hardware-assisted runtime verification in COEMS

Programming in Parallel COMP755

Midterm Exam October 15, 2012 CS162 Operating Systems

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

Synchronization in Concurrent Programming. Amit Gupta

Threads and Parallelism in Java

CS 475. Process = Address space + one thread of control Concurrent program = multiple threads of control

CSCI-1200 Data Structures Fall 2009 Lecture 25 Concurrency & Asynchronous Computing

First Midterm Exam Solutions October 1, 2018 CS162 Operating Systems

Programming Languages

Chapter 4 Concurrent Programming

CS180 Review. Recitation Week 15

(b) External fragmentation can happen in a virtual memory paging system.

CS2102, D15 Exam 1. Name:

Sample Questions. Amir H. Payberah. Amirkabir University of Technology (Tehran Polytechnic)

PRINCIPLES OF OPERATING SYSTEMS

CSE332 Summer 2012 Final Exam, August 15, 2012

CS4411 Intro. to Operating Systems Exam 2 Fall 2009

CS162, Spring 2004 Discussion #6 Amir Kamil UC Berkeley 2/26/04

Concurrent Server Design Multiple- vs. Single-Thread

Transcription:

CS 450 Exam 2 Mon. 11/7/2016 Name: Rules and Hints You may use one handwritten 8.5 11 cheat sheet (front and back). This is the only additional resource you may consult during this exam. No calculators. Include step-by-step explanations and comments in your answers, and show as much of your work as possible, in order to maximize your partial credit. Grade Your Score Max Score Problem 1: Short answer 30 Problem 2: Concurrency warm-up 10 Problem 3: Synchronization 24 Problem 4: Deadlock 11 Problem 5: Scheduling and queues 25 Total 100

Problem 1: Short Answer (30 points) Part A: Definitions (15 points) Define the following terms as they relate to this course. Critical section: Bounded buffer (and its implications for concurrency): Stable system (in the context of queuing theory): 2

Part B: Threads and processes (15 points) Explain the differences between threads and processes, addressing the code segment, the stack, and the heap. How do threads communicate with each other? What about processes? In the context of pthreads code, how can you figure out if a variable is shared between threads or private? 3

Problem 2: Concurrency warm-up (10 points) Consider the following operations on a shared variable with an initial value of 0: Thread 1 x += 2; Thread 2 x += 5; Is the value of x at the end of this code guaranteed to match the value it would have if these statements had been executed sequentially? If yes, explain. If not, explain why not, and how you would fix it. 4

Problem 3: Synchronization (24 points) Part A (12 points) Consider the following function, which is run by multiple threads. All variables that are not declared within the function are global. The function g does not read or modify any shared state. void* f(void * thread_id) { pthread_mutex_t m; pthread_mutex_init(&m); pthread_mutex_lock(&m); long tid = (long) thread_id; for (int i = 0; i < 100000; i++) sum += g(i * tid); } pthread_mutex_unlock(&m); pthread_mutex_destroy(&m); With the current version of the code (where the lock and unlock operations have been commented out), is the value of sum guaranteed to be the same as it would be if f() were called sequentially, once per value of thread id? Explain, and explain how you would correct any errors. If there are 4 threads, how would you expect the performance of this code (changed if necessary for correctness) to compare with the sequential code? Suggest opportunities for improvement. 5

Part B (12 points) Some file has the restriction that a maximum of 3 threads should be accessing it at a time. The code below is the only code that accesses the file. Assume that the lock variable L and the count variable are shared. pthread_mutex_lock(&l); while (count > 3); count++; pthread_mutex_unlock(&l); // Do stuff with the file pthread_mutex_lock(&l); count--; pthread_mutex_unlock(&l); Explain the logic behind this solution and what s wrong with that logic. Give fairly detailed pseudocode for how to fix it using a condition variable (i.e. you don t need to worry about exact pthread syntax, but each line of your pseudocode should map cleanly to a line of real code). 6

Problem 4: Deadlock (11 points) Consider the following processes. The first column shows the maximum amount of some resource that they could ever consume, and the second column shows their current usage of that resource. Max Current A 4 2 B 10 3 C 2 2 D 8 1 Remaining 2 Part A (3 points) Is this system currently in a safe or an unsafe state? 7

Part B (8 points) Here s that table again: Max Current A 4 2 B 10 3 C 2 2 D 8 1 Remaining 2 Put X s in the entries in the table below that would change the state of the system (i.e. would make it unsafe if it s currently safe, or vice versa). Explain your answers if you want partial credit for wrong answers. Is given one more instance of resource Gives back one instance of resource A B C D 8

Problem 6: Scheduling and queueing (25 points) Consider the following tasks in a system whose scheduler has a timeslice of 10 units. Task Arrives at t = Needed CPU time A 0 100 B 10 40 C 20 20 Part A (6 points) What are the completion and response times of each task under a FIFO scheduler? Part B (9 points) Give the values of each of the following quantities based on your answer to Part A. You should just show expressions for these values; no need to simplify them. Throughput Utilization Average number of tasks in system (queued or running) during any given timeslice 9

Here s that table again: Task Arrives at t = Needed CPU time A 0 100 B 10 40 C 20 20 Part C (8 points) Show a timeline for the optimal schedule with respect to average response time. Give the response time of each task. Part D (2 points) What is the downside, if any, of your schedule from Part C? 10