while (1) {
K;
P(mutex);
Add an item to the buffer;
V(mutex);
L;
}
P2
while (1) {
M;
P(mutex);
Remove an item from the buffer;
V(mutex);
N;
}
The statements K, L, M and N are respectively
A |
P(full), V(empty), P(full), V(empty) |
B |
P(full), V(empty), P(empty), V(full) |
C |
P(empty), V(full), P(empty), V(full) |
D |
P(empty), V(full), P(full), V(empty) |
Process P1 is the producer and process P2 is the consumer. Semaphore 'full' is initialized to '0'. This means there is not item if the buffer semaphore 'empty' is initialized to 'n'. This means there is space for n items in the buffer.
In process P1, wait on semaphore 'empty' signifies that if there is no space in buffer then P2 cannot produce more items. Signal on semaphore 'full' is to signify that one item has been added to the buffer.
In process P2, wait on semaphore 'full' signifies that if the buffer is empty then consumer cannot consume any item. Signal on semaphore 'empty' increments a space in the buffer after consumption of an item.