Skip to content
Related Articles

Related Articles

GATE | GATE-IT-2004 | Question 65

View Discussion
Improve Article
Save Article
  • Last Updated : 28 Jun, 2021
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.

while (1) {



Add an item to the buffer;





while (1) {



Remove an item from the buffer;




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)

Answer: (D)

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

Semaphore ‘full’ is initialized to ‘0’. This means there is no item in 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 P1 can not 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 can’t not consume any item. Signal on semaphore ’empty’ increments a space in the buffer after consumption of an item.

Thus, option (D) is correct.

Please comment below if you find anything wrong in the above post.

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!