Question: The following pseudo-code assumes that an infinite buffer is shared between the Producer and Consumer process int n = 0; semaphore s=1 semaphore delay=0;

  1. The following pseudo-code assumes that an infinite buffer is shared between the




The following pseudo-code assumes that an infinite buffer is shared between the Producer and Consumer process int n = 0; semaphore s=1 semaphore delay=0; int main() { } /*number of elements in the infinite buffer */ /*this method starts the execution of producer and consumer in parallel */ void Consumer () { wait (delay); while (true) ( wait (9); int x take(); /* take an element from the infinite buffer */ n signal (s); if (n == 0) consume (x); wait (delay); void Producer () { while (true) ( int x produce (); wait (s); append(x); /* append (add) an element to the infinite buffer"/ n++; if (n=1) signal (delay); signal (s); }} a) This is an incorrect solution to the produce/consumer problem. Explain what exactly is incorrect here. b) How can the problem be fixed? Present your solution by rewriting the incorrect method. (producer, or consumer, or both)

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 Programming Questions!