GateAI
Concurrency and Synchronization

GATE CSE 2022 · Q19

MCQ1 markEasy

Time

Consider the following threads, T1T_1, T2T_2, and T3T_3 executing on a single processor, synchronized using three binary semaphore variables, S1S_1, S2S_2, and S3S_3, operated upon using standard wait() and signal(). The threads can be context switched in any order and at any time. Which initialization of the semaphores would print the sequence BCABCABCA....?

GATE CSE 2022 Q19 diagram

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: C) S1 = 1; S2 = 0; S3 = 0

Concurrency and Synchronization

To print the sequence BCABCABCA..., the execution must strictly follow the cyclic order T2→T1→T3→T2…T_2 \rightarrow T_1 \rightarrow T_3 \rightarrow T_2 \dots

  1. First character 'B':

    • Thread T2T_2 prints 'B' after executing wait(S1).

    • For T2T_2 to execute first without allowing other threads to interleave, we must initialize S1=1S_1 = 1.

    • If either S2=1S_2 = 1 or S3=1S_3 = 1 initially, thread T3T_3 (prints 'A') or T1T_1 (prints 'C') could run first or concurrently, violating the required sequence. Thus, we must have S2=0S_2 = 0 and S3=0S_3 = 0.

  2. Tracing execution with S1=1,S2=0,S3=0S_1 = 1, S_2 = 0, S_3 = 0:

    • T2T_2 runs:wait(S1) sets S1=0S_1 = 0, prints "B", and signal(S3) sets S3=1S_3 = 1.

    • T1T_1 runs:wait(S3) sets S3=0S_3 = 0, prints "C", and signal(S2) sets S2=1S_2 = 1.

    • T3T_3 runs:wait(S2) sets S2=0S_2 = 0, prints "A", and signal(S1) sets S1=1S_1 = 1.

    • The cycle repeats indefinitely, generating the output BCABCABCA... strictly.

Thus, the correct initialization is S1=1;S2=0;S3=0S_1 = 1; S_2 = 0; S_3 = 0, which corresponds to Option (C).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Concurrency and Synchronization previous year question is Q19 of the GATE CSE 2022 paper. Find more GATE CSE PYQs on Concurrency and Synchronization in Operating Systems, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Concurrency and Synchronization PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Concurrency and Synchronization in GATE CSE

Concurrency and Synchronization has 18 GATE CSE PYQs across 15 papers from 2012 to 2026. 3 of them are 1-mark MCQs like this one, and it is the only one in GATE CSE 2022.

How GATE tests Concurrency and Synchronization

More from GATE CSE 2022

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2022 · Q19 · MCQ

Consider the following threads, T1, T2, and T3 executing on a single processor, synchronized using three binary semaphore variables, S1, S2, and S3, operated upon using standard wait() and signal() . The threads can be context switched in any order and at any time. Which initialization of the semaphores would print the sequence BCABCABCA....?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.