CMPSCI 377 Midterm (Sample) Name:

Similar documents
EECS 482 Midterm (Fall 1998)

Queues. A queue is a special type of structure that can be used to maintain data in an organized way.

Midterm Exam Amy Murphy 6 March 2002

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

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

Midterm Exam March 13, 2013 CS162 Operating Systems

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Synchronization Exercise

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

CPS 310 midterm exam #1, 2/17/2017

Last Class: Deadlocks. Today

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

CS 241 Honors Concurrent Data Structures

Threads and concurrency

Threads and concurrency

CSE 120 Principles of Computer Operating Systems Fall Quarter, 2001 Midterm Exam. Instructor: Geoffrey M. Voelker

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

CS315A Midterm Solutions

CS 450 Exam 2 Mon. 4/11/2016

Lecture 9: Midterm Review

UNIVERSITY REGULATIONS

Concurrency User Guide

Stacks and Queues. CSE Data Structures April 12, 2002

Midterm Exam Amy Murphy 19 March 2003

COS 318: Midterm Exam (October 23, 2012) (80 Minutes)

CmpSci 187: Programming with Data Structures Spring 2015

Suggested Solutions (Midterm Exam October 27, 2005)

Midterm Exam Answers

CROWDMARK. Examination Midterm. Spring 2017 CS 350. Closed Book. Page 1 of 30. University of Waterloo CS350 Midterm Examination.

TDDB68 Processprogrammering och operativsystem / Concurrent programming and operating systems

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

Last Class: Synchronization

Chapter 9 STACK, QUEUE

Chapter 6: Process Synchronization

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

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

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

Monitors; Software Transactional Memory

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

COMP 3361: Operating Systems 1 Midterm Winter 2009

CS 318 Principles of Operating Systems

CSE 153 Design of Operating Systems

CSE 410 Final Exam 6/09/09. Suppose we have a memory and a direct-mapped cache with the following characteristics.

Midterm Exam March 3, 1999 CS162 Operating Systems

Midterm I October 19 th, 2009 CS162: Operating Systems and Systems Programming

CSE 120 Principles of Computer Operating Systems Fall Quarter, 2002 Halloween Midterm Exam. Instructor: Geoffrey M. Voelker

Concurrency - II. Recitation 3/24 Nisarg Raval Slides by Prof. Landon Cox and Vamsi Thummala

Review. Preview. Three Level Scheduler. Scheduler. Process behavior. Effective CPU Scheduler is essential. Process Scheduling

CS 140 Midterm Examination Winter Quarter, 2012

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

Mutex Implementation

Eastern Mediterranean University School of Computing and Technology Department of Information Technology. ITEC202 Operating Systems

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

Cpt S 122 Data Structures. Course Review Midterm Exam # 1

Concurrent Objects and Linearizability

TECHNISCHE UNIVERSITEIT EINDHOVEN Faculteit Wiskunde en Informatica

Computer Architecture and Operating Systems Course: International University Bremen Date: Final Examination

Locks. Dongkun Shin, SKKU

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

CPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.

Java Monitors. Parallel and Distributed Computing. Department of Computer Science and Engineering (DEI) Instituto Superior Técnico.

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

CS6235. L15: Dynamic Scheduling

CMPT 125: Practice Midterm Answer Key

Parallelism and Data Synchronization

Threads Tuesday, September 28, :37 AM

Operating Systems (1DT020 & 1TT802)

Today s Topics. u Thread implementation. l Non-preemptive versus preemptive threads. l Kernel vs. user threads

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

1 Process Coordination

PROCESS SYNCHRONIZATION

Grand Central Dispatch. Sri Teja Basava CSCI 5528: Foundations of Software Engineering Spring 10

CMSC421: Principles of Operating Systems

Intro to Threads. Two approaches to concurrency. Threaded multifinger: - Asynchronous I/O (lab) - Threads (today s lecture)

Q1. What is Deadlock? Explain essential conditions for deadlock to occur?

Midterm I March 11 th, 2015 CS162: Operating Systems and Systems Programming

COS 226 Algorithms and Data Structures Fall Midterm

A simple correctness proof of the MCS contention-free lock. Theodore Johnson. Krishna Harathi. University of Florida. Abstract

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

Operating Systems Comprehensive Exam. Fall Student ID # 10/31/2013

Process & Thread Management II. Queues. Sleep() and Sleep Queues CIS 657

Process & Thread Management II CIS 657

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

EECE.4810/EECE.5730: Operating Systems Spring Midterm Exam March 8, Name: Section: EECE.4810 (undergraduate) EECE.

CPS 310 midterm exam #1, 2/17/2017

CSCD 330 Network Programming

Midterm I October 15 th, 2008 CS162: Operating Systems and Systems Programming

CS140 Operating Systems and Systems Programming Midterm Exam

CS106X Handout 24 Winter 2018 February 9 th, 2018 CS106X Midterm Examination

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 4/18/2013

CSE 451 Midterm Exam May 13 th, 2009

Comp 310 Computer Systems and Organization

CS 167 Final Exam. Three Hours; Closed Book May 12, Please write in black ink. Your Name: Your CS Login ID:

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

CS-537: Midterm Exam (Fall 2013) Professor McFlub

Java Semaphore (Part 1)

CMSC421: Principles of Operating Systems

CS-537: Midterm Exam (Spring 2001)

University of Waterloo Midterm Examination Model Solution CS350 Operating Systems

Concurrency: Mutual Exclusion and Synchronization. Concurrency

Problem Set 4 Solutions

Transcription:

CMPSCI 377 Midterm (Sample) You will have 90 minutes to work on this exam, which is closed book. There are 4 problems on 9 pages. Please write your name on EVERY page. You are to abide by the University of Massachusetts Academic Honesty Policy. Name: Problem 1 out of 25 Problem 2 out of 25 Problem 3 out of 25 Problem 4 out of 25 Total out of 100 1

1. Analyzing a Concurrent Program (approx. 20 minutes) The following is an implementation of an atomic transfer function. transfer should atomically dequeue an item from one queue and enqueue it on another. By atomically, we mean that there must be no interval of time during which an external thread can determine that an item has been removed from one queue but not yet placed on another (assuming the external thread locks a queue before examining it). transfer must complete in a finite amount of time, and must allow multiple transfers between unrelated queues to happen in parallel. You may assume the following: queue1 and queue2 never refer to the same queue. queue1 always has an item to dequeue (so dequeue(queue1) succeeds). dequeue, enqueue, thread_lock, and thread_unlock are all written correctly. thread_lock is fair. That is, lock requests are granted in the order of the calls. State whether the implementation (i) works, (ii) doesn t work, or (iii) sometimes works and sometimes doesn t work. If you claim it works, present your reasoning about how you came to this conclusion. If you claim it doesn t work (or only works sometimes), describe the circumstances that cause it not to work, and re-write transfer so it always works (and still meets all the requirements). struct queue int locknum; /* a unique lock number per queue */ item *headptr; /* pointer to the head of the queue */ ; void transfer(struct queue *queue1, struct queue *queue2) item *thing; /* the item being transferred */ thread_lock(queue1->locknum); thread_lock(queue2->locknum); thing = dequeue(queue1); enqueue(queue2, thing); thread_unlock(queue2->locknum); thread_unlock(queue1->locknum); 2

3 Name

2. Writing a Concurrent Program (approx. 20 minutes) You have joined a software company that is writing an implementation of the Banker s algorithm for the UMass Credit Union. They have defined the global variables below. They have also written the function isdangerous(int customer, int amount), which returns 1 if letting the specified customer borrow the specified amount may allow deadlock (otherwise isdangerous returns 0). isdangerous does not modify any global variables. int cash; /* amount of cash currently at the Credit Union */ int creditlimit[customers]; /* each customer s credit limit (the maximum each customer can borrow) */ int currentborrowed[customers]; /* the current amount borrowed by each customer */ Recall the general structure of a thread that uses the Banker s algorithm: declarecreditlimit /* sets creditlimit[customer] */ while (not done) getcash(customer, amount)/* borrow money against credit limit */ do work returnallcash(customer) Your job is to implement the getcash and returnallcash functions. Assume a customer never calls getcash with an amount that would cause him/her to exceed his credit limit. Use monitors (thread_lock, thread_unlock, threadwait, threadsignal, and threadbroadcast) to handle synchronization. Keep your solution as simple as possible. 4

getcash(int customer, int amount) returnallcash(int customer) 5

3. Modified Monitors (approx. 20 minutes) Standard condition variables have no memory of past signals. That is, threadsignal has no effect on threads that call threadwait in the future. Your task is to implement a modified condition variable that remembers past signals. A signal should be delivered to a waiting thread if there are any threads waiting on this condition variable; otherwise, a signal should be saved and delivered to a thread that later waits on this condition variable. Each signal should be delivered to exactly one thread. Assume there is only 1 lock and 1 condition variable. Write pseudo-code for thread_wait_new and thread_signal_new. Here are library functions you may use: Use the test&set instruction (not interrupt_disable) to ensure atomicity in your thread library code. You do not need to worry about interrupts occurring. Use enqueue and dequeue to manipulate thread queues. enqueue adds a thread onto the tail of a queue. dequeue returns the thread at the head of a queue and deletes that thread from the queue. State clearly which queue and thread is being manipulated. Use swapcontext to switch to a new thread. State clearly which thread you are switching to. Use thread_lock_internal and thread_unlock_internal to acquire and release the lock. These are internal versions of thread_lock and thread_unlock that assume atomicity is ensured at the time they are called. State any assumptions you make about how other functions (particularly those that call swapcontext) use test&set. 6

7 Name

4. Test case design (approx. 20 minutes) Consider the following pseudo-code of thread_lock() and thread_unlock(), which allows a lock to be acquired in non-fifo order (i.e. not in the order of calls to thread_lock()). thread_lock(int lockid) while (lock[lockid] == BUSY) add self to this lock s queue; switchtonextreadythread(); // current thread goes to sleep lock[lockid] = BUSY; thread_unlock(int lockid) lock[lockid] = FREE; if (lock s queue is not empty) remove first thread off this lock s queue, and put that thread on the ready queue; Your task is to design a test case that will illustrate that the locks are not always acquired in FIFO order by the above design. The next page has a partially complete test case using three threads T1, T2, and T3. Assume that initially T1, T2, and T3 are added to the ready queue so that T1 will run first, followed by T2, and then T3. The thread library is nonpreemptive. Your task is to modify the code for one or more threads below by inserting at most three thread_yield() operations so that threads request locks in the order T1, T2, T3 but end up acquiring locks in the non-fifo order of T1, T3, T2. No other code besides thread_yield() should be inserted. 8

// Function called by thread T1 void T1_testLocks() thread_lock(1);... print out the lock owner...; thread_unlock(1); // Function called by thread T2 void T2_testLocks() thread_lock(1);... print out the lock owner...; thread_unlock(1); // Function called by thread T3 void T3_testLocks() thread_lock(1);... print out the lock owner...; thread_unlock(1); 9