More review questions for the second midterm COSC 4330/6310.

Slides:



Advertisements
Similar presentations
CAS3SH3 Midterm Review. The midterm 50 min, Friday, Feb 27 th Materials through CPU scheduling closed book, closed note Types of questions: True & False,
Advertisements

Global Environment Model. MUTUAL EXCLUSION PROBLEM The operations used by processes to access to common resources (critical sections) must be mutually.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Section 3. True/False Changing the order of semaphores’ operations in a program does not matter. False.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Chapter 6: Process Synchronization
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
Mutual Exclusion.
SOLUTIONS FOR THE SECOND 4330 QUIZ Jehan-Francois Paris Summer 2014.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
CY2003 Computer Systems Lecture 05 Semaphores - Theory.
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.
Enforcing Mutual Exclusion Message Passing. Peterson’s Algorithm for Processes P0 and P1 void P0() { while( true ) { flag[ 0 ] = false; /* remainder */
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Avishai Wool lecture Introduction to Systems Programming Lecture 4 Inter-Process / Inter-Thread Communication.
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.
Synchronization Principles. Race Conditions Race Conditions: An Example spooler directory out in 4 7 somefile.txt list.c scores.txt Process.
Chapter 2.3 : Interprocess Communication
02/17/2010CSCI 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.
02/19/2007CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
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.
Chapter 6 CPU SCHEDULING.
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 Mutual Exclusion.
6.3 Peterson’s Solution The two processes share two variables: Int turn; Boolean flag[2] The variable turn indicates whose turn it is to enter the critical.
Review Questions on Chapter IV—IPC COSC 4330/6310 Summer 2013.
1 Chapter 2.3 : Interprocess Communication Process concept  Process concept  Process scheduling  Process scheduling  Interprocess communication Interprocess.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 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.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Solutions to Second 4330/6310 Quiz Spring First question Which of the following statements are true or false (2 points) and why? (3 points)
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
CS533 – Spring Jeanie M. Schwenk Experiences and Processes and Monitors with Mesa What is Mesa? “Mesa is a strongly typed, block structured programming.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Lecture Topics: 11/15 CPU scheduling: –Scheduling goals and algorithms.
IPC and IPS Problems Jehan-François Pâris
Agenda  Quick Review  Finish Introduction  Java Threads.
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.
© 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.
Interprocess Communication Race Conditions
CS703 – Advanced Operating Systems
Chapter 5: Process Synchronization – Part 3
IS310 Hardware & Network Infrastructure Ronny L
Concurrency: Mutual Exclusion and Synchronization
Lecture 2 Part 2 Process Synchronization
Problems discussed in the review session for the second midterm
CSE 153 Design of Operating Systems Winter 19
CS333 Intro to Operating Systems
Lecture 18: Coherence and Synchronization
Chapter 3: Process Management
Presentation transcript:

More review questions for the second midterm COSC 4330/6310

Note This presentation contains questions on topics that are on thee second midterm. Depending on the semester, some questions will overlap with the materials that were discussed in the review session.  These materials are based on the questions on the most recent second quiz.

Scheduling How would you simulate a round-robin policy with a time slice of 100 ms on a System V R 4 system? #ts_quantum ts_tqexp ts_slpret ts_maxwait ts_lwait LVL

Answer How would you simulate a round-robin policy with a time slice of 100 ms on a System V R 4 system? #ts_quantum ts_tqexp ts_slpret ts_maxwait ts_lwait LVL #0

Scheduling Consider the following System V Release 4 scheduler: #ts_quantum ts_tqexp ts_slpret ts_maxwait ts_lwait LVL # # # # 3 and assume that a process at priority level 2 receives 800 ms of CPU time before doing an I/O.

Answer 1. Start at priority 2 and get 200 ms of CPU time before returning to the ready queue 2. New priority given by __________

Answer 1. Start at priority 2 and get 200 ms of CPU time before returning to the ready queue 2. New priority given by ts_tqexp 3. Move to priority 1 and get 500 ms of CPU time before returning to the ready queue 4. New priority given by _______

Answer 1. Start at priority 2 and get 200 ms of CPU time before returning to the ready queue 2. New priority given by ts_tqexp 3. Move to priority 1 and get 500 ms of CPU time before returning to the ready queue 4. New priority given by ts_tqexp 5. Move to priority 0 and get 100ms of CPU time before doing an I/O 6. New priority given by _______

Answer 1. Start at priority 2 and get 200 ms of CPU time before returning to the ready queue 2. New priority given by ts_tqexp 3. Move to priority 1 and get 500 ms of CPU time before returning to the ready queue 4. New priority given by ts_tqexp 5. Move to priority 0 and get 200ms of CPU time before doing an I/O 6. New priority given by ts_slpret: level 1

Another answer (I) Step 1: Process is at priority level 2 #ts_quantum ts_tqexp ts_slpret ts_maxwait ts_lwait LVL # # # # 3 and requests 800 ms of CPU time It gets only 200 ms and returns to the CPU queue at the level indicated by ts_tqexp

Another answer (II) Step 2: Process is now at priority level 1 #ts_quantum ts_tqexp ts_slpret ts_maxwait ts_lwait LVL # # # # 3 and requests 600 ms of CPU time It gets only 500 ms and returns to the CPU queue at the level indicated by ts_tqexp

Another answer (III) Step 3: Process is now at priority level 0 #ts_quantum ts_tqexp ts_slpret ts_maxwait ts_lwait LVL # # # # 3 and requests 100 ms of CPU time It gets only the 100 ms then goes to the waiting state

Another answer (IV) Step 4: Process is still at priority level 0 #ts_quantum ts_tqexp ts_slpret ts_maxwait ts_lwait LVL # # # # 3 When it returns to the ready queue, it gets upgraded to the priority level specified by ts_slpret  Goes to priority level 1

Short question What is the major limitation of non-preemptive scheduling policies?

Answer Non-preemptive policies allow processes to monopolize the CPU.

Short question What does the System V Release 4 scheduler do to avoid process starvation?

Answer It increases the priority of processes that have waited more than ts_maxwait time units in the ready queue.

Short question What is the idea behind penalizing processes that have already got their share of the CPU?

Answer To ensure that the other processes can get their fair share of the CPU.

Short question What is the difference between blocking sends and non-blocking sends?

Answer A blocking send waits until the message has been received by the process to which it was addressed A non-blocking send returns as soon as the message has been accepted for delivery.  Like a letter dropped in a mailbox.

Short question Can you simulate a non-blocking send—or receive—using only blocking sends and receives?

Answer No, but you can simulate blocking sends—or receives—using only non-blocking sends and receives.

Short question What is the difference between virtual circuits and datagrams?

Answer Virtual circuits are connection-oriented and ensure that all messages will arrive in the right order without any of them being lost, damaged or duplicated. Datagrams are sent individually.

Short question How would you pass a linked list to a remote procedure?

Answer By storing it in array along with unpacking instructions. A BCDLL4ABCD

Short question How can we solve the big-endian/little endian issue?

Answer We can require all transfers to use an arbitrary network order, the same for all computers.

Short question What is the major advantage of idempotent procedures?

Answer Idempotent procedures can be repeated an arbitrary number of times without causing any harm. Hence, we do not have to worry about incomplete executions.  We restart the procedure.

Short question What is the main disadvantage of atomic transactions?

Answer Their cost.  At the same time they remain indispensable in financial transactions.

Short question What is the difference between the at most once and the all or nothing semantics in RPCs?

Answer The at most once semantics guarantees that no RPC call will be executed more than once but does not prevent partial executions, which the all or nothing semantics does.

Busy waits Why should we avoid busy waits? Is this always true?

Answer Busy waits waste computing cycles. There are especially bad on single processor architectures because the process doing the busy wait will repeatedly interrupt the process on which it is waiting. They are the best solution for short waits on multiprocessor/multicore architectures as long as the expected wait time is less than to context switches.

Problem Consider the function transfer(int *from, int *to, int amount) { *from -= amount; *to += amount; } // transfer and assume the calling sequence: alpha = 100; beta = 200; transfer (&alpha, &alpha, 10)

Problem (continued) What will be the value of alpha after the call assuming that (a) the call was a regular procedure call? (b) the call was a remote procedure call?

Solution (a) If the call was a regular procedure call, a = 100 (b) If the call was a remote procedure call, a = 90 or 110

Explanation With a regular procedure call Calling Program &alpha, &alpha, 10 Debits &alpha Credits same amount to &alpha alpha = 100 doubletrouble

Explanation (cont'd) With a remote procedure call Calling Program doubletrouble 100, 100, 10 alpha = 90 or , 110

What is wrong? shared int reserved[2] = {0, 0}; void enter_region(int pid) { while (reserved[1-pid]); // busy wait reserved[pid] = 1; } // enter_region void leave_region(int pid) { reserved[pid] = 0; } // leave_region

Answer The functions do not guarantee mutual exclusion when processes 0 and 1 enter in lockstep.  The two critical steps are: while (reserved[1-pid]); // test lock reserved[pid] = 1; // set lock

The ice-cream parlor An ice-cream parlor has two employees selling ice cream and six seats for its customers. Each employee can only serve one customer at a time and each seat can only accommodate one customer at a time. Add the required semaphores to the following program skeleton to guarantee that customers will never have to wait for a chair with a melting ice-cream in their hand.

The ice-cream parlor (cont'd) semaphore _______________ = ______; semaphore _______________ = ______; customer (int who) { ______________________________ order_ice_cream(); ______________________________ eat_it(); ______________________________ } // customer

Sketching a solution Two resources are shared by all customers  Six seats  Two employees Questions to ask are  When should we request a resource?  In which order? (very important)  When should we release it?

Solution semaphore _seats__________ = __6___; semaphore _employees______ = _ 2___; customer (int who) { ______________________________ order_ice_cream(); ______________________________ eat_it(); ______________________________ } // customer

Solution (cont'd) semaphore _seats__________ = __6___; semaphore _employees_____ = __2___; customer (int who) { P(&seats); P(&employees);________; order_ice_cream(); ______________________________; eat_it(); ______________________________; // customer Get seat first

Solution (cont'd) semaphore _seats__________ = __6___; semaphore _employees______ = __2___; customer (int who) { P(&seats); P(&employees);________ order_ice_cream(); V(&employees);_________________ eat_it(); ______________________________ } // customer What is missing?

Solution (cont'd) semaphore _seats__________ = __6___; semaphore _employees______ = __2___; customer (int who) { P(&seats); P(&employees);________ order_ice_cream(); V(&employees);_________________ eat_it(); V(&seat);______________________ } // customer

The pizza oven A pizza oven can contain nine pizzas but the oven narrow opening allows only one cook at a time to either put a pizza in the oven or to take one out. Given that there will be more than one cook preparing pizzas at any given time, complete the missing lines in the following C procedure.

The pizza oven (cont'd) semaphore oven = ______; semaphore access = _______; make_pizza(int size, int toppings) { prepare_pizza(size, toppings); ______________________________________ put_into_oven(); ______________________________________ wait_until_done(); ______________________________________ take_from_oven(); ______________________________________ } // make_pizza

Sketching a solution The two resources are already identified  The oven  Access to the oven (mutex) We ask the usual questions  And take care of avoiding mutex-induced deadlocks

Solution semaphore oven = ___9__; semaphore access = __1__; // the mutex make_pizza(int size, int toppings) { prepare_pizza(size, toppings); ______________________________________ put_into_oven(); ______________________________________ wait_until_done(); ______________________________________ take_from_oven(); ______________________________________ } // make_pizza

Solution (cont'd) semaphore oven = ___9__; semaphore access = __1__; // the mutex make_pizza(int size, int toppings) { prepare_pizza(size, toppings); P(&oven); P(&access);__________________ put_into_oven(); ______________________________________ wait_until_done(); ______________________________________ take_from_oven(); ______________________________________ } // make_pizza Order matters!

Solution (cont'd) semaphore oven = ___9__; semaphore access = __ 1__; // the mutex make_pizza(int size, int toppings) { prepare_pizza(size, toppings); P(&oven); P(&access); ____________________ put_into_oven(); V(&access);____________________________ wait_until_done(); P(&access);____________________________ take_from_oven(); V(&oven); V(&access); // IN ANY ORDER!____ } // make_pizza

The pizza oven (again) Redo problem 2 using monitors.

The pizza oven (again) Class oven { private int n_pizzas; // in oven private condition not_full; public void synchronized put_a_pizza() { _______________________________ _______________________________ put_a_pizza_in_the_oven(); ______________________________ ______________________________ } // put_a_pizza()

The pizza oven (again) (Class oven continued) public void synchronized remove_a_pizza() { ______________________________ ______________________________ take_a_pizza_from_the_oven(); ______________________________ ______________________________ } // remove_a_pizza()

The pizza oven (again) (Class oven continued) oven() { n_pizzas = 0; } // constructor } // Class oven

Sketching a solution Two monitor procedures instead of a C function  Each procedure handles a step that must be performed in mutual exclusion Questions to ask are  When do we have to wait on a condition? Must be specific  Which conditions do we need to signal?

Solution Class oven { private int n_pizzas; // in oven private condition not_full; public void synchronized put_a_pizza() { if (n_pizzas == 9) notfull.wait; _____ n_pizzas++;____________________ put_a_pizza_in_the_oven(); ______________________________ ______________________________ } // put_a_pizza()

Solution (cont'd) (Class oven continued) public void synchronized remove_a_pizza() { ____________________________ ____________________________ take_a_pizza_from_the_oven(); n_pizzas--;___________________ notfull.signal;_________________ } // remove_a_pizza()

Solution (cont'd) (Class oven continued) oven() { n_pizzas = 0; } // constructor } // Class oven

More on monitors How should you modify a monitor when you replace its signal calls by notify calls?

More on monitors How should you modify a monitor when you replace its signal calls by notify calls?

Answer How should you modify a monitor when you replace its signal calls by notify calls?  All if( … ) clauses preceding waits should be replaced by while( … ) clauses.

True or false You should always initialize mutex semaphores to one.

Answer You should always initialize mutex semaphores to one.  TRUE

True or false You should always initialize monitor conditions to zero.

Answer You should always initialize monitor conditions to zero.  FALSE monitor conditions have NO VALUE

True or false Many good programmers prefer to put all their signal operations at the end of their monitor procedures.

Answer Many good programmers prefer to put all their signal operations at the end of their monitor procedures.  TRUE Issuing a signal means risking to be interrupted in the middle of its critical section