Question: The following pseudocode ( next page ) is a correct implementation of the producer / consumer problem with a bounded buffer: Labels p 1 ,

The following pseudocode (next page) is a correct implementation of the producer/consumer problem with a bounded buffer:
Labels p1, p2, p3 and c1, c2, c3 refer to the lines of code shown above (p2 and c2 each cover three lines of code). Semaphores empty and full are linear semaphores that can take unbounded negative and positive values. There are multiple producer processes, referred to as Pa, Pb, Pc, etc., and multiple consumer processes, referred to as Ca, Cb, Cc, etc. Each semaphore maintains a FIFO (first-in-first-out) queue of blocked processes. In the scheduling chart below, each line represents the state of the buffer and semaphores after the scheduled execution has occurred. To simplify, we assume that scheduling is such that processes are never interrupted while executing a given portion of code p1, or p2,..., or c3. Your task is to complete the following chart (only run 1 section per line in the chart, multiple sections per line is a special case that you are not supposed to use).
item[4] buffer; // initially empty
semaphore empty; // initialized to +4
semaphore full; // initialized to 0
binary_semaphore mutex; // initialized to 1
void producer()
{
...
while (true){
item = produce();
p1: wait(empty);
/wait(mutex);
p2: append(item);
\signal(mutex);
p3: signal(full);
}
}
void consumer()
{
...
while (true){
c1:wait(full);
/wait(mutex);
c2:item = take();
\signal(mutex);
c3:signal(empty);
consume(item);
}
}
Hint: All processes in this problem will execute 1 section of the code once then continue to the next (i.e. Ca executes c1), unless it is blocked by a semaphore. Update the section of the code executing, the full semaphore value and queue of process names, the buffer (x = full cell, o = empty cell), and the empty semaphore value and queue of process names. (the first few lines are examples).
The following pseudocode ( next page ) is a

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!