COMS 414 - Prelim 1 Review Session Yejin Choi Daniel Williams

Slides:



Advertisements
Similar presentations
1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
Advertisements

Ch 7 B.
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.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: 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.
Cpr E 308 Spring 2004 Recap for Midterm Introductory Material What belongs in the OS, what doesn’t? Basic Understanding of Hardware, Memory Hierarchy.
Review: Chapters 1 – Chapter 1: OS is a layer between user and hardware to make life easier for user and use hardware efficiently Control program.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
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.
02/17/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Module 6: Process Synchronization.
Synchronization CSCI 444/544 Operating Systems Fall 2008.
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.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Background Concurrent.
Chapter 6 Process Synchronization Copyright © 2008.
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.
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.
Chapter 1 Computer System Overview Sections 1.1 to 1.6 Instruction exe cution Interrupt Memory hierarchy Cache memory Locality: spatial and temporal Problem.
Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
Principles of Operating Systems Lecture 6 and 7 - Process Synchronization.
1 Chapter 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Special Machine Instructions for Synchronization Semaphores.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Chap 6 Synchronization. Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 7 Process Synchronization Slide 1 Chapter 7 Process Synchronization.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
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.
Chapter 6: Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
Process Synchronization CS 360. Slide 2 CS 360, WSU Vancouver Process Synchronization Background The Critical-Section Problem Synchronization Hardware.
CSE Operating System Principles Synchronization.
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.
6.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Synchronization Background The Critical-Section Problem Peterson’s.
6.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 6.5 Semaphore Less complicated than the hardware-based solutions Semaphore S – integer.
Deadlock and Starvation
Process Synchronization
Chapter 5: Process Synchronization
Process Synchronization: Semaphores
Process Synchronization
Deadlock and Starvation
Chapter 6-7: Process Synchronization
Chapter 6: Process Synchronization
Chapter 5: Process Synchronization
Process Synchronization
Topic 6 (Textbook - Chapter 5) Process Synchronization
Chapter 5: Process Synchronization
Midterm review: closed book multiple choice chapters 1 to 9
Semaphore Originally called P() and V() wait (S) { while S <= 0
Lecture 22 Syed Mansoor Sarwar
COMS Prelim 1 Review Session
Module 7a: Classic Synchronization
Lecture 2 Part 2 Process Synchronization
Critical section problem
Chapter 5: Process Synchronization
Chapter 6: Synchronization Tools
Process/Thread Synchronization (Part 2)
CSE 542: Operating Systems
CSE 542: Operating Systems
Presentation transcript:

COMS Prelim 1 Review Session Yejin Choi Daniel Williams

program V.S. process ? process V.S. thread ? kernel space V.S. user space? o/s processes V.S. user processes ? kernel-level threads V.S. user-level threads ?

Multitasking (or multithreading…) What is a system call? What is a context switch? What states may a process be in? What is a race condition? What is PCB? Multiprocessor & MultiThreading… HyperThreading…

Critical section Semaphore Monitor

Critical Section Critical section 1. Entry section { 2. Critical section } 3. Exit section 4. Remainder section Critical section design requirements – 1. Mutual Exclusion – 2. Progress – 3. Bounded Waiting

Semaphore Synchronization solutions – Mutex – Spinlock(busy waiting) – Counting semaphore/ Binary semaphore Semaphore Implementation Issues – Deadlock – Starvation

Semaphore Primitives Implementation Busy waiting : Wait(S) { while(S<=0) ; // no-op S--; } Signal(S) { S++; } Block & Wakeup from CPU scheduler: Wait(S) { S--; if( S<0 ) { block( );} } Signal(S) { S++; if( S<=0 ) { wakeup( );} }

Synchronization Three levels of abstraction for concurrent programming: – Hardware instructions Atomic HW instruction ‘test_and_set’ – O/S primitives – Programming language constructs

Monitors monitor condition variables condition variables V.S. semaphores – Condition variable signal( ) … resumes exactly only one suspended process … if no process suspended, no effect at all – Semaphore signal( ) … always affect the state of the semaphore … by increasing resource counter

Sample Monitor Code (….from HW $2-#4-b) monitor readersnwriters { int rcnt = 0, rwaiting = 0, wcnt = 0, wwaiting = 0; condition wantread, wantwrite; int enter_cnt = 1; // the semaphore’s “value” condition wantenter; //... and here’s its wait queue public StartRead() { –-enter_cnt; // this version is allowed to go negative if(enter_cnt < 0) // wait if someone else is inside wantenter.wait(); if(wcnt > 0 || wwaiting > 0) { ++rwaiting; wantread.wait(); --rwaiting; } rcnt++; wantread.signal(); if(++enter_cnt <= 0 && rcnt < 4) // signal the next guy, if any wantenter.signal(); } public EndRead() { if(rcnt == 4) wantenter.signal(); if(--rcnt == 0) wantwrite.signal(); }

Sample Monitor Code – continued public StartWrite() { –-enter_cnt; // just like StartRead if(enter_cnt < 0) wantenter.wait(); if(wcnt == 1 || rcnt > 0) { ++ wwaiting; wantwrite.wait(); --wwaiting; } wcnt = 1; if(++enter_cnt <= 0) wantenter.signal(); } public EndWrite() { wcnt = 0; if(rwaiting > 0) wantread.signal(); else wantwrite.signal(); } }

Classic Synchronization Problems Bounded buffer problem Readers writers problem Dining philosophers problems

Deadlock V.S. Livelock Necessary conditions – Mutual Exclusion, Hold and Wait, No Preemption, Circular Wait Resource Allocation Graph / Wait-For Graph Deadlock Prevention – Ensure one of ‘necessary conditions’ do not hold Deadlock Avoidance – Safe State, Resource-Allocation Graph Algorithm, Banker’s Algorithms

Livelock ( /li:v'lok/ from When two or more processes continuously change their state in response to changes in the other process(es) without doing any useful work. This is similar to deadlock in that no progress is made but differs in that neither process is blocked or waiting for anything.deadlock A human example of livelock would be two people who meet face-to-face in a corridor and each moves aside to let the other pass, but they end up swaying from side to side without making any progress because they always move the same way at the same time.

Resource-allocation graph #1 R1 R P1P2 P3 R3

Resource-allocation graph # P1P2 P3 R3 P4 R1 R2

Deadlock Prevention Make sure that one of the necessary conditions does not hold: 1. Mutual exclusion 2. Hold and Wait 3. No Pre-Emption 4. Circular Wait

Deadlock Avoidance Deadlock Prevention V.S. Deadlock Avoidance Safe State Bankers Algorithm

Make sure to review homework problem sets. Practice writing synchronization code on your own. Rather than reading every single line of the text book, find out key ideas and topics, and try to explain them in your own words.

Synchronization Practice #1 HW $1-#4. boolean waiting [2] = {false, false}; boolean flag = false; CSEnter() { waiting[i] = true; boolean v = true; while (waiting[i] && v) { v = test_and_set(flag); } waiting[i] = false; } CSExit() { if (waiting[j]) { waiting[j] = false; } else { flag = false; }

Synchronization Practice #1 – continued booleanflag = false; booleanwantin[2] = {false, false }; int turn = 0; CSEnter() { boolean v; wantin[i] = true; turn = j; do { v = test_and_set(flag); if(v == false && wantin[j] && turn == j) { // I got in first, but need to defer to the other guy flag = false; v = true; } while(v == true); wantin[i] = false; } CSExit() { flag = false; }

Synchronization Practice #2 HW. $2-#4-a) A CD or DVD burner device can support one process writing to the device, or a maximum of 4 processes concurrently reading from the device. Using semaphores, implement procedures StartRead, StartWrite, EndRead and EndWrite so that (1) these limits will be enforced, and (2) Processes are allowed to access the device in a strict FIFO order. For example if P2 calls StartWrite and has to wait, and then P4 calls StartRead, P2 gets to write before P4 gets to read.

Synchronization Practice #2 - Answer Semaphore wait_queue = 1; Semaphore mutex = 1; Semaphore writer = 1; int rcnt = 0; StartRead() { wait(wait_queue); wait(mutex); if(rcnt == 0) wait(writer); rcnt++; signal(mutex); if(rcnt < 4) signal(wait_queue); } EndRead() { wait(mutex); if(rcnt == 4) signal(wait_queue); if(--rcnt == 0) signal(writer); signal(mutex); } StartWrite() { wait(wait_queue); wait(writer); signal(wait_queue); } EndWrite() { signal(writer); }

Synchronization Practice #3

Synchronization Practice #3 - Answer

Last Verdict…