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 producerconsumer problem with a bounded buffer:
Labels p p p and c c c refer to the lines of code shown above p and c 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 firstinfirstout 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 p or p or c Your task is to complete the following chart only run section per line in the chart, multiple sections per line is a special case that you are not supposed to use
item buffer; initially empty
semaphore empty; initialized to
semaphore full; initialized to
binarysemaphore mutex; initialized to
void producer
while true
item produce;
p: waitempty;
waitmutex;
p: appenditem;
signalmutex;
p: signalfull;
void consumer
while true
c:waitfull;
waitmutex;
c:item take;
signalmutex;
c:signalempty;
consumeitem;
Hint: All processes in this problem will execute section of the code once then continue to the next ie Ca executes c 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
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
