Stuff  Exam timetable now available  Class back in CS auditorium as of Wed, June 4 th  Assignment 2, Question 4 clarification.

Slides:



Advertisements
Similar presentations
Operating Systems: Monitors 1 Monitors (C.A.R. Hoare) higher level construct than semaphores a package of grouped procedures, variables and data i.e. object.
Advertisements

CY2003 Computer Systems Lecture 05 Semaphores - Theory.
6.5 Semaphore Can only be accessed via two indivisible (atomic) operations wait (S) { while S
Dining-Philosophers Problem Shared data fork[5]: semaphore; initialized to 1.
Classic Synchronization Problems
Classical Problems of Concurrency
Operating Systems Process Synchronization. Too Much Pizza 3:00 3:05 3:10 3:15 3:20 3:25 3:30 Person A Look in fridge. Pizza! Leave for store. Arrive at.
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.
Concurrency: Deadlock and Starvation Chapter 6. Revision Describe three necessary conditions for deadlock Which condition is the result of the three necessary.
Process Synchronization
CIS 415 Process Synchronization Background The Critical-Section Problem Software Solutions Semaphores Hardware Support Classical Problems of Synchronization.
1 Chapter 6: Concurrency: Mutual Exclusion and Synchronization Operating System Spring 2007 Chapter 6 of textbook.
CS444/CS544 Operating Systems Classic Synchronization Problems 2/26/2007 Prof. Searleman
Operating System I Process Synchronization. Too Much Pizza 3:00 3:05 3:10 3:15 3:20 3:25 3:30 Person A Look in fridge. Pizza! Leave for store. Arrive.
More Synchronisation Last time: bounded buffer, readers-writers, dining philosophers Today: sleeping barber, monitors.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 23 Classic Synchronization.
© 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.
Critical Problem Revisit. Critical Sections Mutual exclusion Only one process can be in the critical section at a time Without mutual exclusion, results.
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.
Thread Synchronization Tutorial #8 CPSC 261. A thread is a virtual processor Each thread is provided the illusion that it owns a core – Copy of the registers.
1 Previous Lecture Review n Concurrently executing threads often share data structures. n If multiple threads are allowed to access shared data structures.
1 Chapter 2.3 : Interprocess Communication Process concept  Process concept  Process scheduling  Process scheduling  Interprocess communication Interprocess.
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.
Process Synchronization.  Whenever processes share things, there is a chance for screwing up things  For example ◦ Two processes sharing one printer.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 7 Process Synchronization Slide 1 Chapter 7 Process Synchronization.
Chapter 6 Semaphores.
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
Process Synchronization Concurrent access to shared data may result in data inconsistency. Maintaining data consistency requires mechanisms to ensure the.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Synchronization.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 11: Synchronization (Chapter 6, cont)
1 Condition Variables CS 241 Prof. Brighten Godfrey March 16, 2012 University of Illinois.
Synchronisation Examples
Semaphores Ref: William Stallings G.Anuradha. Principle of a Semaphore Two or more processes can cooperate by means of simple signals, such that a process.
CS 241 Section Week #7 (10/22/09). Topics This Section  Midterm Statistics  MP5 Forward  Classical Synchronization Problems  Problems.
CSC 360 Instructor: Kui Wu More on Process Synchronization Semaphore, Monitor, Condition Variables.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Synchronization.
6.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Module 6: Process Synchronization.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 3-3: Process Synchronization Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
CS4315A. Berrached:CMS:UHD1 Process Synchronization Chapter 8.
Process Synchronization CS 360. Slide 2 CS 360, WSU Vancouver Process Synchronization Background The Critical-Section Problem Synchronization Hardware.
Dining Philosophers & Monitors Questions answered in this lecture: How to synchronize dining philosophers? What are monitors and condition variables? What.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 22 Semaphores Classic.
Deadlocks Introduction to Operating Systems: Module 7.
Classic problems of Synchronization : Producers/Consumers problem: The producers/ consumers problem may be stated as follows: Given a set of cooperating.
INTERPROCESS COMMUNICATION Inter process communication (IPC) is a capability supported by operating system that allows one process to communicate with.
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
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.
Semaphore Synchronization tool that provides more sophisticated ways (than Mutex locks) for process to synchronize their activities. Semaphore S – integer.
Process Synchronization: Semaphores
Auburn University COMP 3500 Introduction to Operating Systems Synchronization: Part 4 Classical Synchronization Problems.
Chapter 5: Process Synchronization – Part II
Chapter 5: Process Synchronization
Classical Synchronization Problems
Chapter 6-7: Process Synchronization
Chapter 5: Process Synchronization (Con’t)
Semaphore Originally called P() and V() wait (S) { while S <= 0
Process Synchronization
Synchronization Hank Levy 1.
Chapter 7: Synchronization Examples
Synchronization Hank Levy 1.
Chapter 7: Synchronization Examples
CSE 153 Design of Operating Systems Winter 2019
Problem: CFQ (Circular Fifo Queue)
FIRST SOLUTION Producer Process Consumer Process
Presentation transcript:

Stuff  Exam timetable now available  Class back in CS auditorium as of Wed, June 4 th  Assignment 2, Question 4 clarification

Some Classic Synchronization Problems  Bounded Buffer (Producer/Consumer)  Dining Philosophers Problem  Readers-Writers Problem

Solution of Producer/Consumer: Unbounded Buffer Producer: repeat produce item; wait(mutex); append(item); signal(mutex); signal(number); forever Consumer: repeat wait(number); wait(mutex); item:=take(); signal(mutex); consume item; forever Initialization: mutex.count:=1; //mutual exclusion number.count:=0; //number of items in:=out:=0; //indexes to buffer critical sections append(item): b[in]:=item; in++; take(): item:=b[out]; out++; return item;

Producer/Consumer: Unbounded Buffer  Remarks: Putting signal(number) inside the CS of the producer (instead of outside) has no useful effect since the consumer must always wait for both semaphores before proceeding The consumer must perform wait(number) before wait(signal), otherwise deadlock occurs if consumer enters CS while the buffer is empty. Why?  because it would lock the producer out! Disaster if you forget to do a signal after a wait.  So using semaphores still has pitfalls...  Now let’s look at what happens if the buffer is bounded

Producer/Consumer: Circular Buffer of Size k (Bounded Buffer)  can consume only when number of (consumable) items is at least 1 (now: number != in-out)  can produce only when number of empty spaces is at least 1

Producer/Consumer: Bounded Buffer  Again: Use a semaphore “mutex” for mutual exclusion on buffer access and a semaphore “full” to synchronize producer and consumer on the number of consumable items (full spaces)  But we have to add: a semaphore “empty” to synchronize producer and consumer on the number of empty spaces

Producer/Consumer: Bounded Buffer (Solution) Initialization: mutex.count:=1; //mutual excl. full.count:=0; //full spaces empty.count:=k; //empty spaces Producer: repeat produce item; wait(empty); wait(mutex); append(item); signal(mutex); signal(full); forever Consumer: repeat wait(full); wait(mutex); item:=take(); signal(mutex); signal(empty); consume(item); forever critical sections append(item): b[in]:=item; in=(in+1)mod k; take(): item:=b[out]; out=(out+1)mod k; return item;

The Dining Philosophers Problem (7.5.3)  5 philosophers who only eat and think  each needs to use 2 forks for eating  but we have only 5 forks!  A classical synchronization problem  Illustrates the difficulty of allocating resources among process without deadlock and starvation

The Dining Philosophers Problem 1  Each philosopher is a process  One semaphore per fork  fork: array[0..4] of semaphores  Initialization: fork[i].count:= 1 (for i:=0..4) 5 Philosopher processes Executing in parallel: Process Pi: repeat think; wait(fork[i]); //left wait(fork[i+1 mod 5]);//right eat; signal(fork[i+1 mod 5]);//right signal(fork[i]); //left forever What happens if each philosopher starts by picking his left fork? (Deadlock!)

The Dining Philosophers Problem 2  A solution: allow only 4 philosophers to sit at the table at one time  Then at least 1 philosopher can always eat even if the other 3 are holding 1 fork  Create another semaphore T that limits the number of philosophers at the table  Initialize: T.count:=4 Process Pi: repeat think; wait(T); //get a chair wait(fork[i]); wait(fork[i+1 mod 5]); eat; signal(fork[i+1 mod 5]); signal(fork[i]); signal(T); //get up forever