Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

uestion # Consider the following solution for the bounded-buffer producer-consum

ID: 3603401 • Letter: U

Question

uestion # Consider the following solution for the bounded-buffer producer-consumer problem. One requirement is that the producer must print when the buffer is full and the consumer must print when the buffer is empty semaphore mutex 1; semaphore empty N; semaphore full 0; int inp outp 0; Code for Producer process Code for Consumer process produce (item); wait (empty); wait (mutex); Buffer[inp] item; inp (inp + 1) % N; signal (mutex); signal (full); wait (full); wait (mutex); item Buffer [outp]; out: (outp + 1) % N; signal (mutex); signal (empty); if (empty N) if (full N) printf (“Buffer is empty "); consume (item printf ("Buffer is full "); while (True) while (True) N is the buffer size. There is at least one serious bug (non-syntactic) in the above program. a) Find out all the bugs and describe what problems they can cause b) Fix all the bugs and rewrite the program. In your solution, the producer must print when the buffer is full and the consumer must print when the buffer is empty

Explanation / Answer

Solution:

a)

The bug is in both the methods producer as well as the consumer,

In Consumer:

b)

In producer method:

do{

wai(empty);

wait(mutex);

if(full==N)

printf("Buffer is full ")

and the rest of the lines will be same

in Consumer method:

do{

wai(empty);

wait(mutex);

if(empty==0)

printf("Buffer is emptyl ")

and the rest of the lines will be same

I hope this helps, please let me know in case of any doubt. Thumbs up if this helped.