GateAI
Concurrency and Synchronization

GATE CSE 2013 · Q34

MCQ2 marksHard

Time

A shared variable xx, initialized to zero, is operated on by four concurrent processes W,X,Y,ZW, X, Y, Z as follows. Each of the processes WW and XX reads xx from memory, increments by one, stores it to memory, and then terminates. Each of the processes YY and ZZ reads xx from memory, decrements by two, stores it to memory, and then terminates. Each process before reading xx invokes the PP operation (i.e., wait) on a counting semaphore SS and invokes the VV operation (i.e., signal) on the semaphore SS after storing xx to memory. Semaphore SS is initialized to two. What is the maximum possible value of xx after all processes complete execution?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: D) 2

Concurrency and Synchronization

We are given:

  • Initial value: x=0x = 0

  • Initial semaphore: S=2S = 2 (allowing at most 2 processes in their critical regions simultaneously)

  • Processes W,XW, X: read xx, compute x+1x + 1, write xx

  • Processes Y,ZY, Z: read xx, compute x−2x - 2, write xx

To achieve the maximum possible value of xx, we want the decrement operations of YY and ZZ to be overwritten by the increment operation of WW, and then let XX perform a clean increment:

  1. Process YY executes P(S)P(S)   ⟹  S=1\implies S = 1. It reads local value x=0x = 0.

  2. Process WW executes P(S)P(S)   ⟹  S=0\implies S = 0. It reads local value x=0x = 0.

  3. Process YY resumes, calculates 0−2=−20 - 2 = -2, writes x=−2x = -2, and executes V(S)  ⟹  S=1V(S) \implies S = 1, then terminates.

  4. Process ZZ executes P(S)P(S)   ⟹  S=0\implies S = 0. It reads local value x=−2x = -2.

  5. Process ZZ calculates −2−2=−4-2 - 2 = -4, writes x=−4x = -4, executes V(S)  ⟹  S=1V(S) \implies S = 1, and terminates.

  6. Process WW resumes (having already read x=0x = 0), computes 0+1=10 + 1 = 1, writes x=1x = 1, executes V(S)  ⟹  S=2V(S) \implies S = 2, and terminates. (This completely overwrites the decrements done by YY and ZZ.)

  7. Process XX executes P(S)  ⟹  S=1P(S) \implies S = 1, reads x=1x = 1, computes 1+1=21 + 1 = 2, writes x=2x = 2, executes V(S)  ⟹  S=2V(S) \implies S = 2, and terminates.

Thus, the final and maximum possible value of xx is 2, which corresponds to option (D).

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 Q34 of the GATE CSE 2013 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 GATE CSE 2013 has 3.

How GATE tests Concurrency and Synchronization

More from GATE CSE 2013

Share this solution

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

GateAI solution cardGATE CSE 2013 · Q34 · MCQ

A shared variable x, initialized to zero, is operated on by four concurrent processes W, X, Y, Z as follows. Each of the processes W and X reads x from memory, increments by one, stores it to memory, and then terminates. Each of the processes Y and Z reads x from memory, decrements by two, stores it to memory, and then terminates. Each process before reading x invokes the P operation (i.e., wait) on a counting semaphore S and invokes the V operation (i.e., signal) on the semaphore S after storing x to memory. Semaphore S is initialized to two. What is the maximum possible value of x after all processes complete 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.