Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Operating System: The following is the complete Bounded Buffer program for multiple producers and consumers based on the semaphores. Rewrite the program to solve the

Operating System:

The following is the complete Bounded Buffer program for multiple producers and consumers based on the semaphores.

Rewrite the program to solve the bounded-buffer problem with a monitor (condition variables).

Reminder: the bounded buffer problem is to allow concurrent access to the Buffer by producers and consumers, while ensuring that:

1) The shared Buffer data structure is not screwed up by race condition in accessing it.

2) consumers don't try to remove objects from Buffer when it's empty.

3) Producers don't try to add objects to the Buffer when it's full.

The code:

typeT buf[n]; //an array of some type.

int front = 0;

int rear = 0;

semaphore empty = n, full = 0, mutex = 1;

void produce(typeT date){

wait(empty);

wait(mutex);

buf{rear] = data;

rear = (rear + 1) % n;

signal(mutex);

signal(full);

}

void consume(typeT &result){

wait(full);

wait(mutex);

result = buff[ front ];

front = ( front + 1 ) % n;

signal(mutex);

signal(empty);

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Transaction Processing

Authors: Philip M. Lewis, Arthur Bernstein, Michael Kifer

1st Edition

0201708728, 978-0201708721

More Books

Students also viewed these Databases questions