SOLUTIONS FOR THE SECOND 4330 QUIZ Jehan-Francois Paris Summer 2014.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Copyright © 2000, Daniel W. Lewis. All Rights Reserved. CHAPTER 8 SCHEDULING.
1 Chapter 5 Concurrency: Mutual Exclusion and Synchronization Principals of Concurrency Mutual Exclusion: Hardware Support Semaphores Readers/Writers Problem.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Chapter 6: Process Synchronization
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 91 Today’s class Mutual exclusion and synchronization 
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
Concurrent Processes Lecture 5. Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and.
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
Review: Process Communication Sequential Communication –Result of P1 becomes at termination the input to P2 –Tools: Redirect (>,>>) and Pipe (|) Concurrent.
Synchronization Principles. Race Conditions Race Conditions: An Example spooler directory out in 4 7 somefile.txt list.c scores.txt Process.
02/23/2004CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
1 Outline Processes Threads Inter-process communication (IPC) Classical IPC problems Scheduling.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Intro to OS CUCS Mossé Processes and Threads What is a process? What is a thread? What types? A program has one or more locus of execution. Each execution.
Synchronization CSCI 444/544 Operating Systems Fall 2008.
5.4 Which of the following scheduling algorithms could result in starvation? a. First-come, first-served b. Shortest job first c. Round robin d. Priority.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Semaphores. Readings r Silbershatz: Chapter 6 Mutual Exclusion in Critical Sections.
Chapter III Scheduling Jehan-François Pâris
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Review Questions on Chapter III—Scheduling COSC 4330/6310 Summer 2013.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Introduction to Concurrency.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Mutual Exclusion.
Midterm 1 – Wednesday, June 4  Chapters 1-3: understand material as it relates to concepts covered  Chapter 4 - Processes: 4.1 Process Concept 4.2 Process.
Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus.
Review Questions on Chapter IV—IPC COSC 4330/6310 Summer 2013.
Copyright ©: University of Illinois CS 241 Staff1 Threads Systems Concepts.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Solutions to Second 4330/6310 Quiz Spring First question Which of the following statements are true or false (2 points) and why? (3 points)
More review questions for the second midterm COSC 4330/6310.
Thread Implementations; MUTEX Reference on thread implementation –text: Tanenbaum ch. 2.2 Reference on mutual exclusion (MUTEX) –text: Tanenbaum ch
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Deadlock Operating Systems: Internals and Design Principles.
Problems with Semaphores Used for 2 independent purposes –Mutual exclusion –Condition synchronization Hard to get right –Small mistake easily leads to.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Synchronization Emery Berger and Mark Corner University.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
IPC and IPS Problems Jehan-François Pâris
CE Operating Systems Lecture 8 Process Scheduling continued and an introduction to process synchronisation.
Chapter IX Review Questions and Problems Jehan-François Pâris
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Lecturer 5: Process Scheduling Process Scheduling  Criteria & Objectives Types of Scheduling  Long term  Medium term  Short term CPU Scheduling Algorithms.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Mutual Exclusion Mutexes, Semaphores.
Solutions to the second midterm COSC 4330/6310 Summer 2013.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Semaphores Synchronization tool (provided by the OS) that does not require busy waiting. Logically, a semaphore S is an integer variable that, apart from.
Topics Covered What is Real Time Operating System (RTOS)
Process Synchronization: Semaphores
Background on the need for Synchronization
Concurrency.
Lecture 13: Producer-Consumer and Semaphores
Peculiarity of Peterson’s Solution to Process Synchronization
Concurrency: Mutual Exclusion and Synchronization
Last Week Introduced operating systems Discussed the Kernel
Problems discussed in the review session for the second midterm
First slide Rest of project 2 due next Friday Today:
Lecture 13: Producer-Consumer and Semaphores
CSE 153 Design of Operating Systems Winter 2019
Presentation transcript:

SOLUTIONS FOR THE SECOND 4330 QUIZ Jehan-Francois Paris Summer 2014

First question A cruising boat can carry up to 80 passengers. These passengers can embark or debark through a narrow gangway that can accommodate one person at a time. Add the required semaphore calls to the following two functions to ensure that the boat nor its gangway will never be overloaded. (30 points)

First question semaphore boat = 80; semaphore gangway = 1; embark(){debark()( ________; ________; ________; ________; walk(); walk(); ________; _________; _________; _________; } //embark} //debark

Let us put first the mutex calls semaphore boat = 80; semaphore gangway = 1; embark(){debark()( ________; ________; P(&gangway); P(&gangway); walk(); walk(); V(&gangway); V(&gangway); _________; _________; } //embark} //debark

Then the two other calls semaphore boat = 40; semaphore gangway = 1; embark(){debark()( P(&boat); ________; P(&gangway); P(&gangway); walk(); walk(); V(&gangway); V(&gangway); _________; V(&boat); } //embark} //debark

Second question Consider the following System V.4 scheduler: #ts_quantum ts_tqexp ts_slpret ts_maxwait ts_lwait LVL # # # # 3 Which priority levels will be visited by a process that starts at level 1, waits for 20 seconds, requests 80ms of CPU time and and does an I/O request (2×5 points)

Answer #ts_quantum ts_tqexp ts_slpret ts_maxwait ts_lwait LVL # # # # 3 Which priority levels will be visited by a process that starts at level 1, waits for 20 seconds, requests 80ms of CPU time and does an I/O request (2×5 points) Goes from level 1 to level 2 because ts_lwait Goes from level 2 to level 3 because ts_slpret

Third question What is the main disadvantage of the round- robin CPU scheduling policy?

Third question What is the main disadvantage of the round- robin CPU scheduling policy?  It causes too many context switches at medium to high CPU loads Because we want to keep a good response time for interactive requests

Third question Of all four necessary conditions for deadlocks, which one is the easiest to deny?

Third question Of all four necessary conditions for deadlocks, which one is the easiest to deny?  Circular wait

Third question What is the main advantage of datagrams over virtual circuits and streams?

Third question What is the main advantage of datagrams over virtual circuits and streams?  Much lower overhead

Third question How can you simulate a blocking receive using only non-blocking primitives?

Third question How can you simulate a blocking receive using only non-blocking primitives?  Using a busy wait: while(receive(mbox, buffer, nbytes) ==NO_MSG);

Third question Why do notify primitives are safer to use than the older signal primitives?

Third question Why do notify primitives are safer to use than the older signal primitives?  Because a notify call never interrupts the procedure calling it

Third question What is the best way to prevent starvation in scheduling policies implementing variable priorities?

Third question What is the best way to prevent starvation in scheduling policies implementing variable priorities?  We should increase the priorities of processes that have waited for too long in the ready queue

Fourth question Consider the following solution to the mutual exclusion problem and explain when it fails (5 points) and what happens then. (5 points)

Fourth question shared int reserved[2] = {0, 0}; // global var void enter_region(int pid) { // 0 or 1 int other; other = 1 - pid; // pid of other process reserved[pid] = 1; // reserve while (reserved[other]);// busy wait reserved[pid] = 1; // reserve } // enter_region void leave_region(int pid) { reserved[pid] = 0; } // leave_region

Fourth question shared int reserved[2] = {0, 0}; // global var void enter_region(int pid) { // 0 or 1 int other; other = 1 - pid; // pid of other process reserved[pid] = 1; // reserve while (reserved[other]);// busy wait reserved[pid] = 1; // reserve } // enter_region void leave_region(int pid) { reserved[pid] = 0; } // leave_region The two critical lines

Fourth question shared int reserved[2] = {0, 0}; // global var void enter_region(int pid) { // 0 or 1 int other; other = 1 - pid; // pid of other process reserved[pid] = 1; // reserve while (reserved[other]);// busy wait reserved[pid] = 1; // reserve } // enter_region void leave_region(int pid) { reserved[pid] = 0; } // leave_region Reserve then check: risk of deadlock No tie- breaker

Final answer Solution will cause a deadlock when two processes attempt to enter the critical section in lockstep.

Fifth question Consider the function  void badexchange(int *pa, int *pb) { *pa = *pb; *pb *= *pa; } // badexchange and assume the following calling sequence:  alpha = 3; beta = 5; badexchange (&alpha, &beta);

Fifth question What will be the value of alpha and beta after the call assuming that the call was:  A conventional procedure call? (5 points) alpha = ________ beta = ________  A remote procedure call? (5 points) alpha = ________ beta = ________

The hard case Given  void badexchange(int *pa, int *pb) { *pa = *pb; *pb *= *pa; } // badexchange and the calling sequence  alpha = 3; beta = 5 badexchange (&alpha, &beta); a conventional call would return  alpha = 5 and beta = 25

The easy case Given  void badexchange(int *pa, int *pb) { *pa = *pb; *pb *= *pa; } // badexchange and the calling sequence  alpha = 3; beta = 5; badexchange (&alpha, &beta); an RPC would return  alpha = 5 and beta = 25

Sixth question What is the main advantage of the all or nothing RPC model over the at most once model? (5 points) What is its sole disadvantage ? (5 points)

Sixth question What is the main advantage of the all or nothing RPC model over the at most once model? (5 points)  It eliminates the risk of partial executions of the request Crucial for financial transactions. What is its sole disadvantage ? (5 points)  Its high overhead