Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started