Consider the following two programs in a shared address space. Remember that semaphores are signals (like the flags and lights that railroads use) item buffer [5]; semaphore full (0); semaphore empty (5); semaphore mutex; while (1) { // produce next item to store wait (empty); wait (mutex); // add item to item_buffer signal (mutex); signal (full); while (1) { wait (full); wait (mutex); // remove item from item_buffer; signal (mutex); signal (empty); 11 consume the item } Why must "wait(mutex)" be the last wait performed? • Why does the program on the left wait on the "empty" semaphore, but signal the "full" semaphore? • Why was the "mutex" semaphore added? (What is its purpose?)

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter12: Points, Classes, Virtual Functions And Abstract Classes
Section: Chapter Questions
Problem 19SA
icon
Related questions
Question

Please provide answer with step by step instructions on how to do it. Please also answer the bullet points. 

Consider the following two programs in a shared address space. Remember that semaphores are signals
(like the flags and lights that railroads use)
item buffer [5];
semaphore full (0);
semaphore empty (5);
semaphore mutex;
while (1)
{
// produce next item to store
wait (empty);
wait (mutex);
// add item to item_buffer
signal (mutex);
signal (full);
while (1)
{
wait (full);
wait (mutex);
// remove item from item_buffer;
signal (mutex);
signal (empty);
11 consume the item
}
Why must "wait(mutex)" be the last wait performed?
• Why does the program on the left wait on the "empty" semaphore, but signal the "full"
semaphore?
• Why was the "mutex" semaphore added? (What is its purpose?)
Transcribed Image Text:Consider the following two programs in a shared address space. Remember that semaphores are signals (like the flags and lights that railroads use) item buffer [5]; semaphore full (0); semaphore empty (5); semaphore mutex; while (1) { // produce next item to store wait (empty); wait (mutex); // add item to item_buffer signal (mutex); signal (full); while (1) { wait (full); wait (mutex); // remove item from item_buffer; signal (mutex); signal (empty); 11 consume the item } Why must "wait(mutex)" be the last wait performed? • Why does the program on the left wait on the "empty" semaphore, but signal the "full" semaphore? • Why was the "mutex" semaphore added? (What is its purpose?)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT