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

Similar documents
CS4411 Intro. to Operating Systems Exam 1 Fall points 10 pages

CS4411 Intro. to Operating Systems Final Fall points 12 pages

CS4411 Intro. to Operating Systems Exam 2 Fall 2009

CS4411 Intro. to Operating Systems Final Fall points 10 pages

Chapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6.

Chapter 6: Process Synchronization

Chapter 7: Process Synchronization!

Chapter 7: Process Synchronization. Background. Illustration

Midterm Exam #2 Solutions October 25, 2016 CS162 Operating Systems

Process Synchronization

Chapter 6: Process Synchronization

Chapter 7: Process Synchronization. Background

Chapter 6: Process Synchronization. Module 6: Process Synchronization

CS 31: Introduction to Computer Systems : Threads & Synchronization April 16-18, 2019

C09: Process Synchronization

Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017

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

CS 370 Operating Systems

CHAPTER 6: PROCESS SYNCHRONIZATION

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

CS370 Operating Systems

Concurrency. Chapter 5

COP 4225 Advanced Unix Programming. Synchronization. Chi Zhang

Chapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition

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

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

CS 450 Exam 2 Mon. 4/11/2016

Background. Module 6: Process Synchronization. Bounded-Buffer (Cont.) Bounded-Buffer. Background

CSE 451 Midterm Exam May 13 th, 2009

Operating Systems (1DT020 & 1TT802)

CS3331 Concurrent Computing Exam 1 Solutions Fall 2018

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:

Synchronization. Before We Begin. Synchronization. Credit/Debit Problem: Race Condition. CSE 120: Principles of Operating Systems.

CS420: Operating Systems. Process Synchronization

Introduction to OS Synchronization MOS 2.3

Interprocess Communication By: Kaushik Vaghani

Semaphores. A semaphore is an object that consists of a. methods (e.g., functions): signal and wait. semaphore. method signal. counter.

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

1. Motivation (Race Condition)

Process Coordination

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

Lecture Topics. Announcements. Today: Concurrency (Stallings, chapter , 5.7) Next: Exam #1. Self-Study Exercise #5. Project #3 (due 9/28)

System Software Assignment 8 Deadlocks

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 8: Semaphores, Monitors, & Condition Variables

Reminder from last time

Midterm on next week Tuesday May 4. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 9

CS 537 Lecture 8 Monitors. Thread Join with Semaphores. Dining Philosophers. Parent thread. Child thread. Michael Swift

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

Fall 2004 CS414 Prelim 1

Today: Synchronization. Recap: Synchronization

Module 6: Process Synchronization

Midterm Exam Amy Murphy 19 March 2003

Last Class: Deadlocks. Today

Lecture 9: Midterm Review

Synchronization. Before We Begin. Synchronization. Example of a Race Condition. CSE 120: Principles of Operating Systems. Lecture 4.

EECE.4810/EECE.5730: Operating Systems Spring 2017 Homework 2 Solution

CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio

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

Lesson 6: Process Synchronization

Operating Systems Comprehensive Exam. Spring Student ID # 2/17/2011

CS370 Operating Systems Midterm Review

Processes. Rafael Ramirez Dep Tecnologia Universitat Pompeu Fabra

CSE 120: Principles of Operating Systems. Lecture 4. Synchronization. October 7, Prof. Joe Pasquale

Highlights. - Making threads. - Waiting for threads. - Review (classes, pointers, inheritance)

University of Waterloo Midterm Examination Model Solution CS350 Operating Systems

COMP 3430 Robert Guderian

Process Synchronization Mechanisms

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

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

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; }

Introduction to Operating Systems

CS153: Midterm (Fall 16)

Part II Process Management Chapter 6: Process Synchronization

Fall 2015 COMP Operating Systems. Lab 06

Programming in Parallel COMP755

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

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

MCS-378 Intraterm Exam 1 Serial #:

CS370 Operating Systems

OS Process Synchronization!

CS 450 Exam 2 Mon. 11/7/2016

High Performance Computing Course Notes Shared Memory Parallel Programming

Last Class: CPU Scheduling! Adjusting Priorities in MLFQ!

Module 6: Process Synchronization

PROCESS SYNCHRONIZATION

CS 31: Intro to Systems Misc. Threading. Kevin Webb Swarthmore College December 6, 2018

Operating Systems. Operating Systems Summer 2017 Sina Meraji U of T

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

Operating Systems EDA092, DIT 400 Exam

Background. Old Producer Process Code. Improving the Bounded Buffer. Old Consumer Process Code

First Midterm Exam Solutions October 1, 2018 CS162 Operating Systems

Models of concurrency & synchronization algorithms

Process Synchronization

Resource Sharing & Management

Midterm Exam. October 20th, Thursday NSC

Multitasking / Multithreading system Supports multiple tasks

Chapter 6: Process Synchronization. Operating System Concepts 8 th Edition,

Synchronization Spinlocks - Semaphores

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

Lecture 8: September 30

Transcription:

CS4411 Intro. to Operating Systems Exam 1 Fall 2009 1 CS4411 Intro. to Operating Systems Exam 1 Fall 2009 150 points 9 pages Name: Most of the following questions only require very short answers. Usually a few sentences would be sufficient. Please write to the point. If I don t understand what you are saying, I believe, in most cases, you don t understand the subject. To minimize confusion in grading, please write readable answers. Otherwise, it is very likely I will interpret your unreadable handwriting in my way. Justify your answer with a convincing argument. If there is no justification when it is needed, you will receive no point for that question even though you have provided a correct answer. I consider a good and correct justification more important than a right answer. Thus, if you provide a very vague answer without a convincing argument to show your answer being correct, you will likely receive a low grade. Do those problems you know how to do first. Otherwise, you may not be able to complete this exam on time.

CS4411 Intro. to Operating Systems Exam 1 Fall 2009 2 1. Basic Concepts (a) [10 points] What is the supervisor or kernel mode? What is the user mode? What are the differences? Why are they needed? Note that there are four questions. (b) [10 points] There are three types of schedulers. assigned tasks? What are they and what are their (c) [10 points] Explain the Unix operators <, >, and &. 2. Fundamentals of Processes and Threads (a) [10 points] What is a context? Provide a detail description of all activities of a context switch.

CS4411 Intro. to Operating Systems Exam 1 Fall 2009 3 (b) [15 points] Draw the state diagram of a process from its creation to termination, including all transitions, and briefly elaborate every state and every transition. 3. Synchronization (a) [10 points] Define the meaning of a race condition? Answer the question first and use an execution sequence to illustrate your answer. You will receive no credit if only an example is provided without an elaboration. (b) [10 points] A good solution to the critical section problem must satisfy three conditions: mutual exclusion, progress and bounded waiting. Explain the meaning of the progress condition. Does starvation violate the progress condition? Note that there are two problems. You should provide a clear answer with a convincing argument. Otherwise, you will receive no credit.

CS4411 Intro. to Operating Systems Exam 1 Fall 2009 4 (c) [10 points] The semaphore methods Wait() and Signal() must be atomic to ensure a correct implementation of mutual exclusion. Use an execution sequence to show that if Wait() is not atomic then mutual exclusion cannot be maintained. You must use an execution sequence to present your answer as we did in class. Otherwise, you risk low or zero point. (d) [15 points] We cannot assume any particular order when a process (or thread) is released from a semaphore. A programmer wishes to overcome this problem by implementing a FIFO semaphore so that the waiting processes will be released in a first-in-first-out order. The following is his attempt. In this programmer s mind, a FIFO semaphore consists of an integer counter that is used to simulate a semaphore s counter, and a semaphore queue which is used to enforce the first-in-first-out order. The two corresponding procedures are FIFO_Wait(..) and FIFO_Signal(). To guarantee atomic execution of these two procedures, a semaphore Mutex is used with initial value 1. FIFO_Wait() uses Mutex to lock the procedure and checks the semaphore counter Counter. If this counter is greater than zero, it is decreased by one. Then, FIFO_Wait() releases the procedure and we are all set. If Counter is zero, then the caller is queued. To this end, a semaphore X with initial value 0 is allocated, and added to the end of a semaphore queue. Then, FIFO_Wait() releases the procedure, and lets the caller wait on X. On the other hand, FIFO_Signal() first locks the procedure, and checks if the semaphore queue is empty. If the queue is empty, the counter is increased by one, unlocks the procedure, and returns. However, if there is a waiting process in the queue, the head of the queue is removed and signaled so that the only waiting process on that semaphore can continue. Then, this semaphore node is freed and the procedure is unlocked. Finally, the initialization procedure FIFO_Init(), not shown below, sets the counter to an initial value and the queue to empty.

CS4411 Intro. to Operating Systems Exam 1 Fall 2009 5 Semaphore Mutex = 1; int Counter; FIFO_Wait(...) FIFO_Signal(...) { { Wait(Mutex); Wait(Mutex); if (Counter > 0) { if (queue is empty) { Counter--; Counter++; Signal(Mutex); Signal(Mutex); else { /* must wait here */ else { /* someone is waiting */ allocate a semaphore node, X=0; remove the head X; add X to the end of queue; Signal(X); Signal(Mutex); free X; Wait(X); Signal(Mutex); Discuss the correctness of this solution. If you think it correctly implements a first-infirst-out semaphore, provide a convincing argument to justify your claim. Otherwise, discuss why it is wrong with an execution sequence.

CS4411 Intro. to Operating Systems Exam 1 Fall 2009 6 4. [25 points] Problem Solving: I (a) [25 points] Design a class Barrier in C++, a constructor, and method Barrier_wait() that fulfill the following specification: The constructor Barrier(int n) takes a positive integer argument n, and initializes a private int variable in class Barrier to have the value of n. Method Barrier_wait(void) takes no argument. A thread that calls Barrier_wait() blocks if the number of threads being blocked is less than n-1, where n is the initialization value and will not change in the execution of the program. Then, the n-th calling thread releases all n-1 blocked threads and all n threads continue. Note that the system has more than n threads. Suppose n is initialized to 3. The first two threads that call Barrier_wait() block. When the third thread calls Barrier_wait(), the two blocked threads are released, and all three threads continue. Note that your solution cannot assume n to be 3. Otherwise, you will receive zero point. Use semaphores only to implement class Barrier and method Barrier_wait(). Without observing this rule, you will receive zero point. You may use type Sem for semaphore declaration and initialization (e.g., Sem S = 0; ), Wait(S) on a semaphore S, and Signal(S) to signal semaphore S. You should explain why your implementation is correct in some details. A vague discussion or no discussion receives no credit. Use this and next page for your answer

CS4411 Intro. to Operating Systems Exam 1 Fall 2009 7 (b) [25 points] Let T 0, T 1,..., T n 1 be n threads, and let a[ ] be a global int array. Moreover, thread T i only has access to a[i-1] and a[i] if 0 <i n 1 and thread T 0 only has access to a[n-1] and a[0]. Thus, array a[ ] is circular. Additionally, each thread knows its thread ID, which is a positive integer, and is only available to thread T i. Initially, a[i] contains the thread ID of thread T i. With these assumptions, we hope to find the largest thread ID of these threads. A possible algorithm for thread T i (0 <i n 1) is as follows. Thread T i receives T i 1 s information from a[i-1]. If this information is smaller than T i s thread ID, T i ignores it as T i has a larger thread ID. If this information is larger than T i s thread ID, T i passes it to T i+1 with a[i]. In this way, thread ID s are circulated and smaller ones are eliminated. Finally, if a thread sees the received information is equal to its own, this must be the largest thread ID among all thread ID s. Algorithm for T 0 can be obtained with simple and obvious modifications. Thread T i Thread T_i(...) { // initialization: my thread ID is in a[i] // TID_i is my thread ID while (not done) { if (a[i-1] == -1) { // game over, my thread ID is not the largest break; else if (a[i-1] == TID_i) { // my TID is the largest, break a[i] = -1; // tell everyone to break printf("my thread ID %d is the largest\n", TID_i); break; else if (a[i-1] > TID_i) { // someone s thread ID is larger than mine a[i] = a[i-1]; // pass it to my neighbor else { // so far, my thread ID is still the largest // do nothing // do something else Obviously, race conditions are everywhere. Declare and add semaphores to the above code section so that the indicated task can be performed properly. You may use as many semaphores as you want. However, thread T i can only share its resource, semaphores included, with its left neighbor T i 1 and right neighbor T i+1. To make this problem a bit less complex, you may ignore thread T 0. You may use type Sem for semaphore declaration and initialization (e.g., Sem S = 0; ), Wait(S) on a semaphore S, and Signal(S) to signal semaphore S. You should explain why your implementation is correct in some details. A vague discussion or no discussion receives no credit.

CS4411 Intro. to Operating Systems Exam 1 Fall 2009 8 Use this blank page for your answer

CS4411 Intro. to Operating Systems Exam 1 Fall 2009 9 Grade Report Problem Possible You Received a 10 1 b 10 c 10 a 10 2 b 15 a 10 b 10 3 c 10 d 15 a 25 4 b 25 Total 150