in Operating System
293 views
1 vote
1 vote

The semaphore variables full, empty and mutex are initialized to n, 0 and 1, respectively. Process P1 repeatedly adds one item at a time to a buffer of size n, and process P2 repeatedly removes one item at a time from the same buffer using the programs given below. In the programs, K, L, M and N are unspecified statements.

P1
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

  1. P(full), V(empty), P(full), V(empty)
  2. P(full), V(empty), P(empty), V(full)
  3. P(empty), V(full), P(empty), V(full)
  4. P(empty), V(full), P(full), V(empty)
in Operating System
293 views

1 comment

4?
0
0

1 Answer

0 votes
0 votes

Here process P1 is the producer and process P2 is the consumer.

Semaphore 'full' is initialized to '0',this means there is not item in the buffer.

Semaphore 'empty' is initialized to 'n',this means there is space for n items in the buffer. 

Semaphore 'mutex' is used to guarantee mutual exclusion(initialized to 1)

 

In process P1, wait('empty') signifies that if there is no space in buffer then P2 cannot produce more items. Signal('full') is to signify that one item has been added to the buffer.

Similarly,in process P2, wait('full') signifies that if the buffer is empty then consumer cannot consume any item. Signal('empty') increments a space in the buffer after consumption of an item.

So, answer is (B)

Related questions