GateAI
Concurrency and Synchronization

GATE CSE 2013 · Q39

MCQ2 marksMedium

Time

A certain computation generates two arrays a and b such that a[i]=f(i)a[i] = f(i) for 0≤i<n0 \le i < n and b[i]=g(a[i])b[i] = g(a[i]) for 0≤i<n0 \le i < n. Suppose this computation is decomposed into two concurrent processes XX and YY such that XX computes the array a and YY computes the array b. The processes employ two binary semaphores RR and SS, both initialized to zero. The array a is shared by the two processes. The structures of the processes are shown below.Process X: private i; for (i=0; i<n; i++) { a[i] = f(i); ExitX(R, S); }Process Y: private i; for (i=0; i<n; i++) { EntryY(R, S); b[i] = g(a[i]); }Which one of the following represents the CORRECT implementations of ExitX and EntryY?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: C) ExitX(R, S) { P(S); V(R); } EntryY(R, S) { V(S); P(R); }

Concurrency and Synchronization

To correctly compute b[i]=g(a[i])b[i] = g(a[i]) for each index ii concurrently:

  1. In each iteration ii, Process YY must wait until Process XX finishes computing a[i]a[i] before YY reads a[i]a[i].

  2. Process XX should not overwrite a[i]a[i] in iteration i+1i+1 before Process YY has read a[i]a[i] in iteration ii.

Let both binary semaphores be initialized to 0 (R=0,S=0R = 0, S = 0).

In Option (C):

  • ExitX(R, S): ```cP(S); V(R);```

  • EntryY(R, S): ```cV(S); P(R);```

Trace of execution:

  • In iteration i=0i = 0:

    • Process XX computes a[0]a[0]. Then in ExitX, it performs P(S) and blocks because S=0S = 0.

    • Process YY starts EntryY, performs V(S) which signals SS (unblocking XX), and then executes P(R) which blocks since R=0R = 0.

    • Unblocked Process XX continues and executes V(R), which unblocks Process YY.

    • Process YY is now unblocked and computes b[0]=g(a[0])b[0] = g(a[0]).

  • For each subsequent iteration ii, this strict lockstep handshake alternates smoothly and ensures a[i]a[i] is produced before being consumed, and a[i]a[i] is consumed before a[i+1]a[i+1] is produced.

Thus, (C) is the correct implementation.

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 Q39 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 · Q39 · MCQ

A certain computation generates two arrays a and b such that a[i] = f(i) for 0 ≤ i a and Y computes the array b . The processes employ two binary semaphores R and S, both initialized to zero. The array a is shared by the two processes. The structures of the processes are shown below. Process X: private i; for (i=0; i Process Y: private i; for (i=0; i Which one of the following represents the CORRECT implementations of ExitX and EntryY ?

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.