Consider a version of the bounded buffer problem in which there is two producer processes (P1and P2) and one consumer processes (P3) all sharing the same buffer. Assume that the size of the buffer is n=4, and that we start with a completely empty buffer. The structure of P1, P2, and P3 as well as the semaphores and buffer is shown below:
/* structure of P1 & P2*/do {......produce an item in nextp......wait(empty)wait(mutex)buffer[in]= nextpin = (in + 1) % nsignal(mutex)signal(full)}while(1)
/* structure of P3 */do {wait(full)wait(mutex)nextp = buffer[out]out = (out + 1) % nsignal(mutex)signal(empty)...........consume item in nextp........}while(1)
[ ] item0 [ 0 ] in
[ ] item1 [ 0 ] out
[ ] item0 [ 4 ] empty
[ ] item3 [ 0 ] full
[ 1 ] mutex
Assume a priority scheduler and that all processes start in the ready queue at the same time in the order from head to tail, P1, P2, and P3 (P1 at the head of the queue). The scheduling priorities are P1:1, P2:1, and P3:5. Assume that thesemaphore queues use a priority scheme in which P2 (highest priority) > P1> P3 (lowest priority). Draw the contents of the indices "in" and "out", as well as the state of the semaphores and the contents of the buffer after 2 items have been consumed. In the case of the buffers, simply notate each item with the name of the process that accessed it last.
Draw the contents of the indices "in" and "out", as well as the state of the semaphores and the contents of the buffer after 2 items have been consumed. In the case of the buffers, simply notate each item with the name of the process that accessed it last.
[ ] item0 [ ] in
[ ] item1 [ ] out
[ ] item0 [ ] empty
[ ] item3 [ ] full
[ ] mutex