# GATE - 2006 | OS | The wait and signal operations of a monitor are implemented using ## Question:

The wait and signal operations of a monitor are implemented using semaphores as follows. In the following,

• x is a condition variable,
• mutex is a semaphore initialized to 1,
• x_sem is a semaphore initialized to 0,
• x_count is the number of processes waiting on semaphore x_sem, initially 0, next is a semaphore initialized to 0,
• next_count is the number of processes waiting on semaphore next, initially 0.

The body of each procedure that is visible outside the monitor is replaced with the following:

P(mutex);

body of procedure

if (next_count > 0)

V(next);

else

V(mutex);

• Each occurrence of x.wait is replaced with the following:

x_count = x_count + 1;

if (next_count > 0)

V(next)

else

V(mutex);

------------------------------------------------------------ E1;

x_count = x_count - 1;

• Each occurrence of x.signal is replaced with the following:

if (x_count > 0)

{

next_count = next_count + 1;

------------------- E2;

P(next),

next_count = next_count - 1;

}

For correct implementation of the monitor, statements E1 and E2 are, respectively,

 A P(x_sem), V(next) B V(next), P(x_sem) C P(next), V(x_sem) D P(x_sem), V(x_sem)

## Solution:

### Option (D) is Correct.

x_count is the no. of processes waiting on semaphore x_sem, initially 0.

x_count is incremented and decremented in x_wait, which shows that in between them wait(x_sem) must happen which is P(x_sem).

Correspondingly V(x_sem) must happen in x_signal.

So, D choice.

Thank You
{"ft_lang_label":"__label__en","ft_lang_prob":0.79510766,"math_prob":0.9362951,"size":1066,"snap":"2022-27-2022-33","text_gpt3_token_len":283,"char_repetition_ratio":0.21186441,"word_repetition_ratio":0.0,"special_character_ratio":0.3499062,"punctuation_ratio":0.16145833,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9955329,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,2,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-07-07T17:22:30Z\",\"WARC-Record-ID\":\"<urn:uuid:df413e81-28b8-4f53-b5d4-db7b06d6ad0a>\",\"Content-Length\":\"30114\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:4b6aed11-dd58-4ae5-bc27-142fc8bcbf16>\",\"WARC-Concurrent-To\":\"<urn:uuid:00f7bc3d-27ee-4192-b495-d090fefcb02a>\",\"WARC-IP-Address\":\"104.21.13.50\",\"WARC-Target-URI\":\"https://govtvacancy.net/sarkari-job/gate-2006-os-the-wait-and-signal-operations-of-a-monitor-are-implemented-using-2\",\"WARC-Payload-Digest\":\"sha1:VYP7O2UXDTUBVB4EMEZBASR2TIVNWJYK\",\"WARC-Block-Digest\":\"sha1:2HKR6IBRMSREZ5N4QM25ARQAIE5FENCG\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656104495692.77_warc_CC-MAIN-20220707154329-20220707184329-00261.warc.gz\"}"}