GateAI
Concurrency and Synchronization

GATE CSE 2024 Set 1 · Q40

MCQ2 marksMedium

Time

Consider the following two threads T1 and T2 that update two shared variables aa and bb. Assume that initially a=b=1a = b = 1. Though context switching between threads can happen at any time, each statement of T1 or T2 is executed atomically without interruption. T1 a = a + 1;b = b + 1; T2 b = 2 * b;a = 2 * a; Which one of the following options lists all the possible combinations of values of aa and bb after both T1 and T2 finish execution?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: A) (a = 4, b = 4); (a = 3, b = 3); (a = 4, b = 3)

Concurrency and Synchronization

Let the individual atomic statements be:

  • S1S_1: a = a + 1; (from T1)

  • S2S_2: b = b + 1; (from T1)

  • S3S_3: b = 2 * b; (from T2)

  • S4S_4: a = 2 * a; (from T2)

Within thread T1, S1S_1 must execute before S2S_2. Within thread T2, S3S_3 must execute before S4S_4. The total number of valid interleavings is (42)=6\binom{4}{2} = 6:

  1. S1→S2→S3→S4S_1 \rightarrow S_2 \rightarrow S_3 \rightarrow S_4:

    • S1S_1: a=1+1=2a = 1 + 1 = 2

    • S2S_2: b=1+1=2b = 1 + 1 = 2

    • S3S_3: b=2×2=4b = 2 \times 2 = 4

    • S4S_4: a=2×2=4a = 2 \times 2 = 4

    • Result:(a=4,b=4)(a = 4, b = 4)

  2. S1→S3→S2→S4S_1 \rightarrow S_3 \rightarrow S_2 \rightarrow S_4:

    • S1S_1: a=2a = 2

    • S3S_3: b=2×1=2b = 2 \times 1 = 2

    • S2S_2: b=2+1=3b = 2 + 1 = 3

    • S4S_4: a=2×2=4a = 2 \times 2 = 4

    • Result:(a=4,b=3)(a = 4, b = 3)

  3. S1→S3→S4→S2S_1 \rightarrow S_3 \rightarrow S_4 \rightarrow S_2:

    • S1S_1: a=2a = 2

    • S3S_3: b=2b = 2

    • S4S_4: a=4a = 4

    • S2S_2: b=3b = 3

    • Result:(a=4,b=3)(a = 4, b = 3)

  4. S3→S1→S2→S4S_3 \rightarrow S_1 \rightarrow S_2 \rightarrow S_4:

    • S3S_3: b=2b = 2

    • S1S_1: a=2a = 2

    • S2S_2: b=3b = 3

    • S4S_4: a=4a = 4

    • Result:(a=4,b=3)(a = 4, b = 3)

  5. S3→S1→S4→S2S_3 \rightarrow S_1 \rightarrow S_4 \rightarrow S_2:

    • S3S_3: b=2b = 2

    • S1S_1: a=2a = 2

    • S4S_4: a=4a = 4

    • S2S_2: b=3b = 3

    • Result:(a=4,b=3)(a = 4, b = 3)

  6. S3→S4→S1→S2S_3 \rightarrow S_4 \rightarrow S_1 \rightarrow S_2:

    • S3S_3: b=2×1=2b = 2 \times 1 = 2

    • S4S_4: a=2×1=2a = 2 \times 1 = 2

    • S1S_1: a=2+1=3a = 2 + 1 = 3

    • S2S_2: b=2+1=3b = 2 + 1 = 3

    • Result:(a=3,b=3)(a = 3, b = 3)

Thus, the set of all distinct final values for (a,b)(a, b) is:

{(a=4,b=4),  (a=3,b=3),  (a=4,b=3)}\{(a = 4, b = 4),\; (a = 3, b = 3),\; (a = 4, b = 3)\}

This matches Option (A).

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 Q40 of the GATE CSE 2024 Set 1 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. 9 of them are 2-mark MCQs like this one, and it is the only one in GATE CSE 2024 Set 1.

How GATE tests Concurrency and Synchronization

More from GATE CSE 2024 Set 1

Share this solution

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

GateAI solution cardGATE CSE 2024 Set 1 · Q40 · MCQ

Consider the following two threads T1 and T2 that update two shared variables a and b. Assume that initially a = b = 1. Though context switching between threads can happen at any time, each statement of T1 or T2 is executed atomically without interruption. T1 a = a + 1; b = b + 1; T2 b = 2 * b; a = 2 * a; Which one of the following options lists all the possible combinations of values of a and b after both T1 and T2 finish execution?

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.