HW1 and Synchronization & Queuing

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
CAS3SH3 Midterm Review. The midterm 50 min, Friday, Feb 27 th Materials through CPU scheduling closed book, closed note Types of questions: True & False,
Chapter 6: Process Synchronization
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
CS 241 Spring 2007 System Programming 1 Queuing Framework for Process Management Evaluation Lecture 20 Klara Nahrstedt.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 13: October 12, 2010 Instructor: Bhuvan Urgaonkar.
6.5 Semaphore Can only be accessed via two indivisible (atomic) operations wait (S) { while S
Classic Synchronization Problems
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Synchronization (Or The “Joys” of Concurrent.
Process Synchronization
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.
Condition Variables Revisited Copyright ©: University of Illinois CS 241 Staff1.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Exam Review Operating Systems CS 550. Items of Interest Exam is Nov. 19, 2014 Focus on material since last exam, though knowledge of initial material.
CS 153 Design of Operating Systems Spring 2015 Lecture 11: Scheduling & Deadlock.
1 Processes, Threads, Race Conditions & Deadlocks Operating Systems Review.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Classical problems.
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.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 14: October 14, 2010 Instructor: Bhuvan Urgaonkar.
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.
Synchronizing Threads with Semaphores
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 11: Synchronization (Chapter 6, cont)
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
CS 241 Section Week #7 (10/22/09). Topics This Section  Midterm Statistics  MP5 Forward  Classical Synchronization Problems  Problems.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Synchronization.
6.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Module 6: Process Synchronization.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
CE Operating Systems Lecture 8 Process Scheduling continued and an introduction to process synchronisation.
Web Server Architecture Client Main Thread for(j=0;j
6.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 6.5 Semaphore Less complicated than the hardware-based solutions Semaphore S – integer.
Semaphores Synchronization tool (provided by the OS) that does not require busy waiting. Logically, a semaphore S is an integer variable that, apart from.
Process Synchronization: Semaphores
Auburn University COMP 3500 Introduction to Operating Systems Synchronization: Part 4 Classical Synchronization Problems.
Background on the need for Synchronization
Process Synchronization
Chapter 5: Process Synchronization – Part II
Chapter 5: Process Synchronization
Applied Operating System Concepts -
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Chapter 5: Process Synchronization (Con’t)
Critical Section and Critical Resources
Andy Wang Operating Systems COP 4610 / CGS 5765
Critical Section and Critical Resources
COT 5611 Operating Systems Design Principles Spring 2014
Midterm review: closed book multiple choice chapters 1 to 9
Semaphore Originally called P() and V() wait (S) { while S <= 0
Process Synchronization
Module 7a: Classic Synchronization
Operating System Concepts
Chapter 7: Synchronization Examples
Semaphores Chapter 6.
Concurrency: Mutual Exclusion and Process Synchronization
Lecture 18 Syed Mansoor Sarwar
Chapter 6 Synchronization Principles
Chapter 7: Synchronization Examples
CSE 451 Section 1/27/2000.
CSE 153 Design of Operating Systems Winter 2019
EECE.4810/EECE.5730 Operating Systems
CSE 542: Operating Systems
CSE 542: Operating Systems
Presentation transcript:

HW1 and Synchronization & Queuing CS241 Discussion Section Spring 2009 Week 7

TA Review Optional TA Review Session The TAs will hold an optional review session to answer last-minute exam questions: Saturday, March 14, 2009 2pm – 4pm 2405 SC

Outline HW1 Discussion Synchronization problems Queueing theory Producer-consumer Dining Philosophers Queueing theory

HW1 a) int *x, q=0; *x = q; (a): ________ b) int b[2]; *b = 20; (b): ________ c) char greet[80]; strcpy (‘‘Hello’’, greet); (c): ________

HW1 a) int *x, q=0; *x = q; (a): Incorrect b) int b[2]; *b = 20; (b): Correct c) char greet[80]; strcpy (‘‘Hello’’, greet); (c): Incorrect

HW1 d) int *p, q[2]; p = malloc (sizeof (int)); *p = 3; q[2]=*p; (d): ________ e) int *x, y; x = &y; *x = 10; (e): ________

HW1 d) int *p, q[2]; p = malloc (sizeof (int)); *p = 3; q[2]=*p; (d): Incorrect e) int *x, y; x = &y; *x = 10; (e): Correct

HW1 Which scheduling policy a) minimizes average task waiting time? _______ b) minimizes average task response time? ________ c) suffers the convoy effect? ________ d) has the largest context switch overhead? _______ e) may suffer a starvation effect? ______

HW1 Which scheduling policy a) minimizes average task waiting time? ___SJF_____ b) minimizes average task response time? ____RR_____ c) suffers the convoy effect? ____FIFO_____ d) has the largest context switch overhead? ____RR_____ e) may suffer a starvation effect? ___SJF___

HW1 while (x > 0) {}; x ++; /* assume this line is atomic */ execute critical section; x – –; /* assume this line is atomic */ Mutual exclusion: Progress:

HW1 while (x > 0) {}; x ++; /* assume this line is atomic */ execute critical section; x – –; /* assume this line is atomic */ Mutual exclusion: No Progress: Yes

HW1 x2 = 1; x1 = 1; while (x1 != 0) {}; while (x2 != 0) {}; critical section; critical section; x2 = 0; x1 = 0; Mutual exclusion: Progress:

HW1 x2 = 1; x1 = 1; while (x1 != 0) {}; while (x2 != 0) {}; critical section; critical section; x2 = 0; x1 = 0; Mutual exclusion: Yes Progress: No

HW1 while (y = = 1) {}; while (y = = 0) {}; y = 1; y = 0; critical section; critical section; Mutual exclusion: Progress:

HW1 while (y = = 1) {}; while (y = = 0) {}; y = 1; y = 0; critical section; critical section; Mutual exclusion: No Progress: No

HW 1 Function g() calls function f(). Function g() creates a POSIX thread that executes function f(). Kill – Exec – Exit –

HW 1 Function g() calls function f(). control passes from function g() to function f() then returns to g() when f() ends. b) Function g() creates a POSIX thread that executes function f(). when the new thread is created, f() executes concurrently with g(). Kill – sends a signal to a process Exec – runs a new program in the current address space Exit – terminates a unix process

HW1 - Change behavior of SIGUSR1 Block SIGINT Which of these? sleep alarm sigwait sigprocmask sigaction sigsuspend

HW1 - Change behavior of SIGUSR1 Block SIGINT Which of these? sleep alarm sigwait sigprocmask sigaction sigsuspend

HW1 a) The turnaround time minus the _______ time is equal to the waiting time. b) The turnaround time is the time from the process creation time to its _____ time. b) The total time a process spends in queues is called ______ time d) Response time is the interval from ______ time to _____ time

HW1 a) The turnaround time minus the execution time is equal to the waiting time. b) The turnaround time is the time from the process creation time to its finish time. b) The total time a process spends in queues is called waiting time d) Response time is the interval from arrival time to start time

Example 1: Producer-Consumer Problem Producers insert items Consumers remove items Shared bounded buffer e.g. a circular buffer with an insert and a removal pointer.

Producer-Consumer insertPtr removePtr

Producer-Consumer insertPtr removePtr

Producer-Consumer insertPtr removePtr

Producer-Consumer insertPtr removePtr

Producer-Consumer insertPtr removePtr

Producer-Consumer insertPtr removePtr

Producer-Consumer insertPtr removePtr

Producer-Consumer BUFFER FULL: Producer must be blocked! insertPtr removePtr

Producer-Consumer insertPtr removePtr

Producer-Consumer removePtr insertPtr

Producer-Consumer removePtr insertPtr

Producer-Consumer removePtr insertPtr

Producer-Consumer removePtr insertPtr

Producer-Consumer removePtr insertPtr

Producer-Consumer removePtr insertPtr

Producer-Consumer BUFFER EMPTY: Consumer must be blocked! removePtr insertPtr

Challenge Need to prevent: Buffer Overflow Buffer Underflow Producer writing when there is no storage Buffer Underflow Consumer reading nonexistent data Race condition Two processes editing the list at the same time

Synchronization variables Create these variables to prevent these problems: items semaphore Counts how many items are in the buffer Cannot drop below 0 slots semaphore Counts how may slots are available in the buffer list mutex Makes buffer access mutually exclusive

Producer-Consumer Example ds7-problem1.c shows an example implementation for one producer and one consumer, but without synchronization code. Running it shows Buffer underflows Nonsense data is consumed Buffer overflows Unconsumed data is overwritten

Example 2: Dining Philosophers

Dining Philosopher Challenge { Think | Eat } N Philosophers circular table with N chopsticks To eat the Philosopher must first pickup two chopsticks ith Philosopher needs ith & i+1st chopstick Only put down chopstick when Philosopher has finished eating Devise a solution which satisfies mutual exclusion but avoids starvation and deadlock

The simple implementation while(true) { think() lock(chopstick[i]) lock(chopstick[(i+1) % N]) eat() unlock(chopstick[(i+1) % N]) unlock(chopstick[i]) } Does this work?

Deadlocked! When every philosopher has picked up his left chopstick, and no philosopher has yet picked up his right chopstick, no philosopher can continue. Each philosopher waits for his right neighbor to put a chopstick down, which he will never do. This is a deadlock.

Formal Requirements for Deadlock Mutual exclusion Exclusive use of chopsticks Hold and wait condition Hold 1 chopstick, wait for next No preemption condition Cannot force another to undo their hold Circular wait condition Each waits for next neighbor to put down chopstick The simple implementations satisfies all of these.

Problems for Week 7 1) ds7-problem1.c contains producer-consumer code. Use the provided semaphores and mutexes to prevent buffer overflows, underflows, and race conditions. Think: When should the consumer block? When should the producer block?

Problems for Week 7 (contd) 2) ds7-problem2.c contains dining philosophers code. Alter the program to prevent deadlock. There are multiple ways to do this. Think: What are the conditions of deadlock? Can any of them be removed?

Queuing Theory

Queuing Diagram for Processes Exit Start Ready Queue CPU Time Slice Event Event Queue

Queueing Theory Steady state Poisson arrival with l constant arrival rate (customers per unit time) each arrival is independent. P( t£t ) = 1- e–lt 0.5 1 Av λ t

Analysis of Queueing Behavior Probability n customers arrive in time interval t is: e–lt (lt) n/ n! Assume random service times (also Poisson): m constant service rate (customers per unit time)

Queuing Diagram for Processes Exit Start ARRIVAL RATE l SERVICE RATE m Time Slice SERVICE RATE m1 ARRIVAL RATE l1 Event Queue

Useful Facts From Queuing Theory Wq= mean time a customer spends in the queue l = arrival rate Lq = l Wq number of customers in queue W = mean time a customer spends in the system L = l W ( Little's theorem) number of customers in the system In words – average length of queue is arrival rate times average waiting time

Analysis of Single Server Queue Server Utilization: r = l/m Time in System: W = 1/(m-l) Time in Queue: Wq = r/(m-l) Number in Queue (Little): Lq = r2/(1-r)

Poisson Arrival & Service Rates Sum ARRIVAL RATE l1 Server Input Queue SERVICE RATE m ARRIVAL RATE l2 l = l1+ l2

TA Review Optional TA Review Session The TAs will hold an optional review session to answer last-minute exam questions: Saturday, March 14, 2009 2pm – 4pm 2405 SC