GATE - 2004 | OS | The semaphore variables full, empty and mutex are initialized to 0, n

GATE - 2004 | OS | The semaphore variables full, empty and mutex are initialized to 0, n
Posted on 22-02-2022

GATE - 2004 [Operating System]

Question:

The semaphore variables full, empty and mutex are initialized to 0, n and 1, respectively. Process P1 repeatedly adds one item at a time to a buffer of size n, and process Prepeatedly 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

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)

Solution:

Option (D) is Correct.

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.

Thank You

Download App for Free PDF Download

GovtVacancy.Net Android App: Download

government vacancy govt job sarkari naukri android application google play store https://play.google.com/store/apps/details?id=xyz.appmaker.juptmh