Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The bounded buffer problem is a result of producing and consuming work asynchronously at different and/or variable rates. Provided below are implementations for producer and

The bounded buffer problem is a result of producing and consuming work asynchronously at different and/or variable rates. Provided below are implementations for producer and consumer functions which use semaphores to solve the bounded buffer problem:

int data[8], i0 = 0, i1 = 0;

semaphore mutex = 1; semaphore empty = 8; semaphore full = 0;

void producer() { while (1) { wait(empty); wait(mutex); // LINE 1 data[i0] = (i0 + (i0 * i1)) % 32; i0 = ++i0 % 16; signal(mutex); // LINE 2 signal(full); } }

void consumer() { while (1) { wait(full); wait(mutex); printf("%d ", data[i1]); i1 = ++i1 % 16; signal(mutex); signal(empty); } }

What would happen if the commented lines in the producer function (LINE1 & LINE2) were removed? Would the implementation still solve the bounded buffer problem? If so, explain what effects removing these lines would have on the execution of the functions. If not, why are those lines necessary to solving the bounded buffer problem? Justify your answer.

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

Understanding Databases Concepts And Practice

Authors: Suzanne W Dietrich

1st Edition

1119827949, 9781119827948

More Books

Students also viewed these Databases questions

Question

What are three advantages of a civil service system?

Answered: 1 week ago