Producer-Consumer One common situation: Producers and consumers communicate via a buffer.

Slides:



Advertisements
Similar presentations
Ch 7 B.
Advertisements

Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
1 Semaphores and Monitors CIS450 Winter 2003 Professor Jinhua Guo.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 13: October 12, 2010 Instructor: Bhuvan Urgaonkar.
University of Pennsylvania 9/21/00CSE 3801 Concurrent Process Synchronization (Lock and semaphore) CSE 380 Lecture Note 5 Insup Lee.
Enforcing Mutual Exclusion, Semaphores. Four different approaches Hardware support Disable interrupts Special instructions Software-defined approaches.
1 Synchronization Coordinating the Activity of Mostly Independent Entities.
Synchronization CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
6/16/2015 Chapter Eight Process Synchronisation. Index Objectives Concurrent processes and Asynchronous concurrent processes Process synchronisation Mutual.
Language Support for Concurrency. 2 Common programming errors Process i P(S) CS P(S) Process j V(S) CS V(S) Process k P(S) CS.
CS470 Lab 4 TA Notes. Objective Simulate the activities of a producer and consumer – Page 326 Use thread synchronization to solve the producer-consumer.
1 Reader-writer Problem w/ Additional Requirement I Reader-writer problem: Share a buffer which holds one item (an integer) A single reader and writer.
Classical Synchronization Problems. Paradigms for Threads to Share Data We’ve looked at critical sections –Really, a form of locking –When one thread.
Language Support for Concurrency. 2 Announcements CS 415 project 1 due today! CS 414 homework 2 available due next week Midterm will be first week in.
IPC and Classical Synchronization Problems
Slide 8-1 Copyright © 2004 Pearson Education, Inc. Basic Synchronization Principles.
Basic Synchronization Principles. Concurrency Value of concurrency – speed & economics But few widely-accepted concurrent programming languages (Java.
© 2004, D. J. Foreman 1 Mutual Exclusion © 2004, D. J. Foreman 2  Mutual exclusion ■ Critical sections ■ Primitives  Implementing it  Dekker's alg.
Classical Synchronization Problems. Announcements CS 414 grades and solutions available in CMS soon. –Average 74.3 –High of 95. –Score out of 100 pts.
Condition Variables Revisited Copyright ©: University of Illinois CS 241 Staff1.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Chapter 6(b): Synchronization.
CS4231 Parallel and Distributed Algorithms AY 2006/2007 Semester 2 Lecture 2 (19/01/2006) Instructor: Haifeng YU.
Message passing model. buffer producerconsumer PRODUCER-CONSUMER PROBLEM.
Semaphores and Bounded Buffer Andy Wang Operating Systems COP 4610 / CGS 5765.
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.
Semaphores and Bounded Buffer. Semaphores  Semaphore is a type of generalized lock –Defined by Dijkstra in the last 60s –Main synchronization primitives.
1 Using Semaphores CS 241 March 14, 2012 University of Illinois Slides adapted in part from material accompanying Bryant & O’Hallaron, “Computer Systems:
Lecture 6: Synchronization (II) – Semaphores and Monitors
CSE 451: Operating Systems Winter 2012 Semaphores and Monitors Mark Zbikowski Gary Kimura.
Module 2.1: Process Synchronization
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 11: Synchronization (Chapter 6, cont)
CSE 451: Operating Systems Winter 2014 Module 8 Semaphores, Condition Variables, and Monitors Mark Zbikowski Allen Center 476 ©
1 Condition Variables CS 241 Prof. Brighten Godfrey March 16, 2012 University of Illinois.
13/03/07Week 21 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
Concurrency in Shared Memory Systems Synchronization and Mutual Exclusion.
1 Semaphores n Semaphores  Issues addressed:  1. Problems with busy-waiting  2. Definition of a semaphore: init(s), P(s) and V(s) - invariant  3. Examples.
Operating Systems: A Modern Perspective, Chapter 8 Slide 8-1 Copyright © 2004 Pearson Education, Inc.
6.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Module 6: Process Synchronization.
Producer-Consumer Problem David Monismith cs550 Operating Systems.
Message passing model. buffer producerconsumer PRODUCER-CONSUMER PROBLEM.
Operating Systems NWEN 301 Lecture 6 More Concurrency.
CSE 451: Operating Systems Spring 2006 Module 8 Semaphores and Monitors John Zahorjan Allen Center 534.
Auburn University COMP 3500 Introduction to Operating Systems Synchronization: Part 4 Classical Synchronization Problems.
“Language Mechanism for Synchronization”
Classical Synchronization Problems
Synchronization Methods
More on Classic Synchronization Problems, Monitors, and Deadlock
© 2013 Gribble, Lazowska, Levy, Zahorjan
The Critical-Section Problem (Two-Process Solution)
Sarah Diesburg Operating Systems COP 4610
An object-based synchronization mechanism.
Semaphores and Bounded Buffer
Semaphore Originally called P() and V() wait (S) { while S <= 0
Process Synchronization
CSE 451: Operating Systems Autumn 2010 Module 8 Semaphores, Condition Variables, and Monitors Ed Lazowska Allen Center 570.
© 2013 Gribble, Lazowska, Levy, Zahorjan
Invariant Based Methodology
CSE 451: Operating Systems Winter Module 8 Semaphores and Monitors
Steve’s Concurrency Slides
CSE 451: Operating Systems Autumn Module 8 Semaphores and Monitors
CSE 451: Operating Systems Winter Module 7 Semaphores and Monitors
CSE 451: Operating Systems Winter Module 7 Semaphores and Monitors
Outline Announcements Basic Synchronization Principles – continued
CSE 451: Operating Systems Winter Module 7 Semaphores and Monitors
CIS 720 Lecture 6.
Outline Please turn in Homework #2 Announcements
Steve’s Concurrency Slides
Review The Critical Section problem Peterson’s Algorithm
Presentation transcript:

Producer-Consumer One common situation: Producers and consumers communicate via a buffer.

Producer() { while (1) { >> P(empty); /* Get an empty buffer (decrease count), block if unavail */ P(mutex); /* acquire critical section: shared buffer */ >> V(mutex); /* release critical section */ V(full); /* increase number of full buffers */ } Producer

Consumer() { while (1) { P(full); P(mutex); <<< critical section: Remove item from shared buffer */ V(mutex); V(empty); } Consumer

Reader-Writer Problem Another common situation: Readers and writers must access a common data structure. Multiple readers are allowed, but only one writer. This solution allows readers to starve writers.

Writer() { while (1) { P(writing); >> V (writing); } Writer

Reader() { while (1) { P(mutex); rd_count++; if (1 == rd_count) P(writing); V(mutex); >> P(mutex) rd_count--; if ( 0 == rd_count) V(writing); V(mutex); } } Reader