Synchronization III: Summary CPE 261403 - Operating Systems

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

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.
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
Monitors A high-level abstraction that provides a convenient and effective mechanism for process synchronization Only one process may be active within.
COSC 3407: Operating Systems Lecture 8: Semaphores, Monitors and Condition Variables.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
1 CS 333 Introduction to Operating Systems Class 5 – Semaphores and Classical Synchronization Problems Jonathan Walpole Computer Science Portland State.
5.6.2 Thread Synchronization with Semaphores Semaphores can be used to notify other threads that events have occurred –Producer-consumer relationship Producer.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Synchronization (Or The “Joys” of Concurrent.
CS444/CS544 Operating Systems Synchronization 2/21/2007 Prof. Searleman
Chapter 2.3 : Interprocess Communication
Semaphores CSCI 444/544 Operating Systems Fall 2008.
02/25/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.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
1 Chapter 5 Concurrency. 2 Concurrency 3 4 Mutual Exclusion: Hardware Support Test and Set Instruction boolean testset (int *i) { if (*i == 0) { *i.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Module 6: Process Synchronization.
More Synchronisation Last time: bounded buffer, readers-writers, dining philosophers Today: sleeping barber, monitors.
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.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 14: October 14, 2010 Instructor: Bhuvan Urgaonkar.
Synchronization II: CPE Operating Systems
Process Synchronization I Nov 27, 2007 CPE Operating Systems
1 Chapter 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Special Machine Instructions for Synchronization Semaphores.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
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 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  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 24 Critical Regions.
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
6.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Module 6: Process Synchronization Codes.
Problems with Semaphores Used for 2 independent purposes –Mutual exclusion –Condition synchronization Hard to get right –Small mistake easily leads to.
Synchronisation Examples
CSC 360 Instructor: Kui Wu More on Process Synchronization Semaphore, Monitor, Condition Variables.
Process Synchronization CS 360. Slide 2 CS 360, WSU Vancouver Process Synchronization Background The Critical-Section Problem Synchronization Hardware.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 22 Semaphores Classic.
1 Advanced Operating Systems - Fall 2009 Lecture 7 – February 2, 2009 Dan C. Marinescu Office: HEC 439 B. Office hours:
Chapter 71 Monitor for Reader/Writers  Synchronizes access if all processes follow.  If some don’t go through monitor and database is accessed directly,
Process Synchronization. Objectives To introduce the critical-section problem, whose solutions can be used to ensure the consistency of shared data To.
Process Synchronization I CPE Operating Systems
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
CS 311/350/550 Semaphores. Semaphores – General Idea Allows two or more concurrent threads to coordinate through signaling/waiting Has four main operations.
Deadlock and Starvation
Dining Philosophers Five philosophers sit around a table
Semaphores Synchronization tool (provided by the OS) that does not require busy waiting. Logically, a semaphore S is an integer variable that, apart from.
Semaphore Synchronization tool that provides more sophisticated ways (than Mutex locks) for process to synchronize their activities. Semaphore S – integer.
Auburn University COMP 3500 Introduction to Operating Systems Synchronization: Part 4 Classical Synchronization Problems.
Process Synchronization
Deadlock and Starvation
Operating Systems CMPSC 473
Chapter 6-7: Process Synchronization
Chapter 6: Process Synchronization
Chapter 5: Process Synchronization (Con’t)
Semaphore Originally called P() and V() wait (S) { while S <= 0
Process Synchronization
Lecture 22 Syed Mansoor Sarwar
Synchronization Hank Levy 1.
Chapter 7: Synchronization Examples
Synchronization Hank Levy 1.
Chapter 7: Synchronization Examples
CSE 153 Design of Operating Systems Winter 2019
Loading… Please Wait $ $ $100 $100 $100 $100 $100 $200 $200 $200 $200 $300 $300 $300 $300 $300 $400 $400 $400 $400 $400 $500 $500 $500 $500 $500.
Problem: CFQ (Circular Fifo Queue)
FIRST SOLUTION Producer Process Consumer Process
Presentation transcript:

Synchronization III: Summary CPE Operating Systems

Synchronization Topics Critical Section Limiting Concurrent Resource Access Sequencing Events

What’s wrong the code on the left? int Mutex = 1; while (Mutex == 0); Mutex--; // Critical Section Mutex++; Semaphore Mutex = 1; Wait (Mutex); // Critical Section Signal(Mutex);

Non-Atomic instruction Register1 = Mutex Decrease register1 Mutex = register1 Register2 = Mutex Decrease register2 Mutex = register2 Register1 = Mutex Register2 = Mutex Decrease register2 Mutex = register2 Decrease register1 Mutex = register1

Semaphore Wait(s)Signal(s)

Busy Waiting while (Mutex == 0);Wait (Mutex); Very high CPU load!

Semaphore vs Monitor

Critical Section Semaphore mutex=1; int count=0; void add() { wait(mutex); count++; signal(mutex); } int count=0; Monitor doStuff { Void add() { count++; }

Limiting Concurrent Resource Access Semaphore db=3; void connectDb() { wait(db); connect(); signal(db); } int MaxDb=3; Monitor doStuff { Void connectDb() { if (MaxDb > 0){ MaxDb--; connect(); MaxDb++; }

Sequencing Events Semaphore buffer=0; void consume() { wait(buffer); removeItem(); } Void Produce() { addItem(); signal(buffer); } Monitor doStuff { Condition buffer; Void consume() { if (bufferLen==0) buffer.wait(); removeItem(); } Void Produce() { addItem(); buffer.signal() }