Producer-Consumer Problem Variation. In class, we reviewed the Producer-Consumer problem, which used semaphores to control access to a bounded buffer where a Producer process would produce data items and add them to the buffer and one Consumer would remove data items from the buffer and consume them (please refer to slide 18 in the Week 9 PowerPoint or Figure 5.16 in the course textbook for the pseudocode for this problem). As a variation of that problem, assume the bounded buffer size is 12. Assume the Producer process enters 3 items at a time into the buffer. It will only do this if there are at least 3 empty spots in the buffer. Assume the Consumer process will remove items 2 at a time, and will only do so if there are at least 2 items in the buffer. In addition to the Producer and Consumer processes, assume there is a third Hybrid process. Each time it accesses the buffer its role changes. One time it is a Producer entering a single item, and the next time it is a Consumer removing a single item.  Write pseudocode similar to Figure 5.16 in the textbook to handle this situation (make sure you change the values for any semaphores as necessary and provide implementations for the Producer, Consumer, and Hybrid processes).

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Producer-Consumer Problem Variation. In class, we reviewed the Producer-Consumer problem, which used semaphores to control access to a bounded buffer where a Producer process would produce data items and add them to the buffer and one Consumer would remove data items from the buffer and consume them (please refer to slide 18 in the Week 9 PowerPoint or Figure 5.16 in the course textbook for the pseudocode for this problem). As a variation of that problem, assume the bounded buffer size is 12. Assume the Producer process enters 3 items at a time into the buffer. It will only do this if there are at least 3 empty spots in the buffer. Assume the Consumer process will remove items 2 at a time, and will only do so if there are at least 2 items in the buffer. In addition to the Producer and Consumer processes, assume there is a third Hybrid process. Each time it accesses the buffer its role changes. One time it is a Producer entering a single item, and the next time it is a Consumer removing a single item.  Write pseudocode similar to Figure 5.16 in the textbook to handle this situation (make sure you change the values for any semaphores as necessary and provide implementations for the Producer, Consumer, and Hybrid processes).

/* program boundedbuffer */
const int sizeofbuffer - /* buffer size */;
semaphore s = 1, n= 0, e= sizeofbuffer;
void producer()
{
while (true) {
produce ();
semWait (e);
semWait (s);
append ();
semsignal (s);
semsignal (n);
void consumer()
{
while (true) {
semWait (n);
semWait (s);
take ();
semsignal (s);
semsignal (e);
consume();
void main()
{
parbegin (producer, consumer);
Figure 5.16 A Solution to the Bounded-Buffer Producer/Consumer
Problem Using Semaphores
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Transcribed Image Text:/* program boundedbuffer */ const int sizeofbuffer - /* buffer size */; semaphore s = 1, n= 0, e= sizeofbuffer; void producer() { while (true) { produce (); semWait (e); semWait (s); append (); semsignal (s); semsignal (n); void consumer() { while (true) { semWait (n); semWait (s); take (); semsignal (s); semsignal (e); consume(); void main() { parbegin (producer, consumer); Figure 5.16 A Solution to the Bounded-Buffer Producer/Consumer Problem Using Semaphores © 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Parallel and Distributed Storage
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education