CPS 310 midterm exam #1, 2/19/2016 Your name please: ___________________ NetID:___________ /40 /40 /50.

Slides:



Advertisements
Similar presentations
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Advertisements

Ch 7 B.
Chapter 6: Process Synchronization
Background Concurrent access to shared data can lead to inconsistencies Maintaining data consistency among cooperating processes is critical What is wrong.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 13: October 12, 2010 Instructor: Bhuvan Urgaonkar.
Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 91 Today’s class Mutual exclusion and synchronization 
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Objectives Understand.
5.6.2 Thread Synchronization with Semaphores Semaphores can be used to notify other threads that events have occurred –Producer-consumer relationship Producer.
02/17/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
CPS110: Implementing threads/locks on a uni-processor Landon Cox.
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.
02/19/2007CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
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.
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.
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
(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.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 11: October 5, 2010 Instructor: Bhuvan Urgaonkar.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
Process Synchronization. Concurrency Definition: Two or more processes execute concurrently when they execute different activities on different devices.
6.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 6.5 Semaphore Less complicated than the hardware-based solutions Semaphore S – integer.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Tutorial 2: Homework 1 and Project 1
Deadlock and Starvation
/50 /60 /40 /30 A Tale of Two Clients
Process Management Process Concept Why only the global variables?
CS 6560: Operating Systems Design
Chapter 6: Process Synchronization
Process Synchronization
Background on the need for Synchronization
Deadlock and Starvation
Concurrency.
Chapter 5: Process Synchronization
Concurrency: Mutual Exclusion and Synchronization
Chapter 26 Concurrency and Thread
Topic 6 (Textbook - Chapter 5) Process Synchronization
Semaphore Originally called P() and V() wait (S) { while S <= 0
Thread Implementation Issues
Lecture 2 Part 2 Process Synchronization
Critical section problem
Grades.
Concurrency: Mutual Exclusion and Process Synchronization
Chapter 6: Process Synchronization
CSE 153 Design of Operating Systems Winter 19
CS333 Intro to Operating Systems
Chapter 6: Synchronization Tools
CSE 153 Design of Operating Systems Winter 2019
CSE 451 Section 1/27/2000.
EECE.4810/EECE.5730 Operating Systems
CSE 542: Operating Systems
Don Porter Portions courtesy Emmett Witchel
Sarah Diesburg Operating Systems CS 3430
Presentation transcript:

CPS 310 midterm exam #1, 2/19/2016 Your name please: ___________________ NetID:___________ /40 /40 /50 /50 Answer all questions. Please attempt to confine your answers to the boxes provided. For the execution tracing problem (P3) you may wish to use scratch paper to keep things clean. There is a synchronization/coding problem at the end. As always: “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.” If you don’t know the answer to a question, then just say something else relevant for partial credit. /20 /200 P1. Shorts: kernel and machine (40 points) What happens when a thread executes code to disable interrupts while it is running in user mode? Disabling interrupts is often sufficient to synchronize critical sections if a machine has only one processor core, but not if there are multiple cores. Why? On a system call trap, how does the kernel determine which system call in the kernel API is being requested? When a thread executes an instruction referencing a virtual address, how does the machine determine which virtual address space to use in translating the address? How does the kernel determine if a given address translation fault is a “segmentation fault”, i.e., a wild pointer reference?

CPS 310 midterm exam #1, 2/19/2016, page 2 of 5 P2. Thread primitives and the thread lifecycle (40 points) As threads execute, they transition through various states (ready, running, blocked). As threads transition among these states, their thread control blocks (TCBs) move among various queues maintained by the thread system. These state changes and queue operations are driven by calls to thread primitives in the thread system API. Below are five thread primitives defined for the lab p1. For each primitive, list the thread state changes it may cause as it executes, and the associated queue operations. (a) thread_yield(…) (b) thread_lock(…) (c) thread_unlock(…) (d) thread_wait(…) (e) thread_signal(…)

CPS 310 midterm exam #1, 2/19/2016, page 3 of 5 P3. Trace that schedule (50 points) Consider the following pseudocode for a soda machine with N=1: the machine has buffer space for a single soda (initially empty). This problem asks you to trace execution of this code in detail for the given main program. Assume that the code runs on a uniprocessor (single core) with no involuntary preemptions: thus the schedule is deterministic. Trace the schedule as an ordered list containing every thread state change. The thread primitives behave as in lab p1: all queues are FIFO, as required for p1t. The threads are named P0 (main), P1, C0, and C1. It may help to list queue contents at various points. P0 runs …<continue below> main_thread_starts_here() { thread_create(consume, …); /* C0 */ thread_create(consume, …); /* C1 */ thread_create(produce, …); /* P1 */ thread_yield(); produce(); /* P0 */ } void produce(…) { thread_lock(1); while (full) { thread_yield(); thread_wait(1, 2); } add soda; thread_signal(1, 2); thread_unlock(1); void consume(…) { thread_lock(1); while (empty) { thread_yield(); thread_wait(1, 2); } take soda; thread_signal(1, 2); thread_unlock(1);

CPS 310 midterm exam #1, 2/19/2016, page 4 of 5 Part P4. Highway 310 (50 points) Highway 310 is a two-lane road that passes through a one-lane tunnel. A car can safely enter the tunnel if and only if there are no oncoming cars already in the tunnel. To prevent collisions, sensors at each end of the tunnel notify a controller program when cars arrive or depart. The controller sets a boolean variable free and a direction variable dir to control signal lights for approaching cars at either end of the tunnel: if free is true, then the lights are green in both directions. If free is false, then dir=0 sets the lights to allow eastbound traffic to pass, and dir=1 sets them to allow westbound traffic to pass. Show how to implement the controller using a monitor. You may assume that each car is represented by a thread that calls Arrive() and Depart() methods. Threads should block in Arrive() if the light is red for their direction, and wake up and continue through when the light is green. Arrive() and Depart() each take two integer arguments. An eastbound car passes the values 0 and 1. A westbound car passes the values 1 and 0. Your solution should be free of collisions and starvation. boolean free = true; int dir = 0; Arrive (int myway, int otherway) { } Depart (int myway, int otherway) { }

CPS 310 midterm exam #1, 2/19/2016, page 5 of 5 Part 5. Analysis of the P3 trace (20 points) Answer the following questions about the schedule in Part 3. Also consider possible executions of the “stripped” version, which is the same code, but with the five calls to thread_yield() removed. Describe the final state of the trace in a single word or sentence. Is a different outcome possible if the thread_create calls are reordered? (Explain.) Does the “stripped” version have a different outcome, i.e., do the calls to thread_yield affect the result? What outcomes are possible in the “stripped” version if it runs with preemption enabled? (Explain.) What changes would you make to the “stripped” code before deploying it in production?