Question: The following program solves producer/consumer problem with limited buffer of size 3: /* program producer_consumer*/ Const int buffer_size= 3 Semaphore lock =1; Semaphore n=-1; Semaphore

The following program solves producer/consumer problem with limited buffer of size 3:

/* program producer_consumer*/

Const int buffer_size= 3

Semaphore lock =1;

Semaphore n=-1;

Semaphore f= buffer_size;

Voide procedure()

{

While (true)

{

Produce();

SemWait(f);

SemWait(lock);

append;

semSignal(lock);

semSignal(n)

}

}

Voide consumer()

{

While (true)

{

SemWait(n);

SemWait(lock);

take;

semSignal(lock);

semSignal(f)

}

}

void main()

{

Parbegin (producer and consumer)

}

1. Try to trace the above program in the following sequence: - producer starts first and produces two items then the consumer can start to consume one item.

2. Is there any problem in part 1? if there is, show what this problem and try to solve it.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!