Process Coordination Name Due 1. Consider a version of the bounded buffer proble
ID: 3595585 • Letter: P
Question
Process Coordination Name Due 1. Consider a version of the bounded buffer problem in which there are one producer process (Pi) and two consumer processes (P2 and Ps) 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 P, P2, and Ps as well as the semaphores and buffer is shown below: /" structure ot Pl / / structure of P2 & P3 / do t item 0 item 1 item 2 item3 do t wait (ful1) wait (mutex) nextp buffer[out] out- (out + 1) % n signal (mutex) signal (empty) produce an item in nextp wait (empty) wait (mutex) bufferlin]- nextp in=(in + 1) % n signal (mutex) signal (full) in out consume item in nextp 4 empty o full )while (1) while (1) mutex Assume a preemptive scheduler and that all processes start in the ready queue at the same time in the order from head to tail, P3, P2, and P1 (P3 at the head of the queue). Let the process priorities be: P3 =1,P2 = 1,and P1-2. 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.Explanation / Answer
In Ready queue we are having elements P3 P2 P1 in that order.
Given P3 is the 1st process in the ready queue and P1 is the last one.
Now P3 will start its execution and perform the operation wait(full),
Here initially full =0 and hence this operation will be unsuccessful
and P3 will be moved into suspend queue.
Now the next process P2 will start its execution and perform the operation wait(full),
Here initially full =0 and hence this operation will be unsuccessful
and P2 will be moved into suspend queue.
Now the processes that are blocked and waiting in
suspend queue are P3 P2 in that order.
Now P1 will start its execution and perform the operation wait(empty),
Here initially empty = 4 and hence this operation will be successful
and empty = 3 [ wait(empty) ]
mutex = 0 [ wait(mutex) ]
in = 1 [ in = (in + 1) % n]
mutex = 1 [ signal(mutex) ]
full = 1 [ signal(full) ]
Now after performing the operation signal(full) the 1st process in
suspend queue P3 will be waked up.
Now P3 and P1 are in ready queue but P3 will execute 1st as its priority = 1.
P3 will start its execution and perform the operation wait(full),
Here full =1 and hence this operation will be successful
Here mutex =1 and hence this operation will be successful
After these wait operations now
full = 0
mutex = 0
out = 1 [ out = (out + 1) % n ]
mutex = 1 [signal(mutex) ]
empty = 4 [ signal(empty) ]
Now P1 will start its execution and perform the operation wait(empty),
Here empty = 4 and hence this operation will be successful
and empty = 3 [ wait(empty) ]
mutex = 0 [ wait(mutex) ]
in = 2 [ in = (in + 1) % n]
mutex = 1 [ signal(mutex) ]
full = 1 [ signal(full) ]
Now after performing the operation signal(full) the 2nd process in
suspend queue P2 will be waked up.
Now P2 and P1 are in ready queue but P2 will execute 1st as its priority = 1.
P2 will start its execution and perform the operation wait(full),
Here full =1 and hence this operation will be successful
Here mutex =1 and hence this operation will be successful
After these wait operations now
full = 0
mutex = 0
out = 2 [ out = (out + 1) % n ]
mutex = 1 [signal(mutex) ]
empty = 4 [ signal(empty) ]
Hence after 2 items consumed status is
in = 2
out = 2
full = 0
mutex = 1
empty = 4
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.