GateAI
Processes, Threads and IPC

GATE CSE 2019 · Q23

NAT1 markHard

Time

Consider three concurrent processes P1, P2 and P3 as shown below, which access a shared variable D that has been initialized to 100. Refer to the table below. The processes are executed on a uniprocessor system running a time-shared operating system. If the minimum and maximum possible values of D after the three processes have completed execution are X and Y respectively, then the value of Y − X is _______.

GATE CSE 2019 Q23 diagram

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 80 (±0)

Processes, Threads and IPC

Each statement D=D+kD = D + k consists of three atomic operations:

  1. READ(D) into a local register

  2. ADD constant kk to the local register

  3. WRITE the local register value back to DD

Initially, D=100D = 100.

  • P1P_1: D=D+20D = D + 20

  • P2P_2: D=D−50D = D - 50

  • P3P_3: D=D+10D = D + 10

To minimize DD (XX):

  • P2P_2 reads D=100D = 100 and is preempted before writing back (D−50=50D - 50 = 50).

  • P1P_1 and P3P_3 run to completion: DD becomes 100+20+10=130100 + 20 + 10 = 130.

  • P2P_2 resumes and writes its local value 5050 to DD.

  • Therefore, minimum value X=50X = 50.

To maximize DD (YY):

  • P1P_1 reads D=100D = 100 and is preempted before writing back (D+20=120D + 20 = 120).

  • P2P_2 and P3P_3 run to completion: DD becomes 100−50+10=60100 - 50 + 10 = 60.

  • P1P_1 resumes and writes its local value 120120 to DD.

  • Alternatively, if P3P_3 reads D=100D=100, P1P_1 finishes (120120), P2P_2 finishes (7070), and P3P_3 writes 110110, the maximum achieved is 120120 using P1P_1 or 130130 if P2P_2 is overwritten.

  • Let's check: P2P_2 reads D=100D = 100, preempted. Then P1P_1 and P3P_3 execute fully, setting D=100+20+10=130D = 100 + 20 + 10 = 130. P2P_2 writes 5050—this was for minimum.

  • If P2P_2 reads D=100D=100 and is preempted, then P1P_1 and P3P_3 run sequentially: D=100+20+10=130D = 100 + 20 + 10 = 130. If P2P_2 writes 5050 before P1P_1 or P3P_3 completes, the maximum value remaining at the end without interruption would simply be if P2P_2 runs first (D=50D=50), and then P1P_1 and P3P_3 add 3030, resulting in 8080. But if P2P_2's decrement is completely lost (overwritten), say P2P_2 reads 100100, P1P_1 reads 100100, P2P_2 writes 5050, then P1P_1 writes 120120, and then P3P_3 runs: D=120+10=130D = 120 + 10 = 130.

  • Thus, maximum value Y=130Y = 130.

Calculating Y−XY - X:

Y−X=130−50=80Y - X = 130 - 50 = 80

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 Processes, Threads and IPC previous year question is Q23 of the GATE CSE 2019 paper. Find more GATE CSE PYQs on Processes, Threads and IPC 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 Processes, Threads and IPC 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.

Processes, Threads and IPC in GATE CSE

Processes, Threads and IPC has 15 GATE CSE PYQs across 13 papers from 2011 to 2026. 3 of them are 1-mark NAT questions like this one, and GATE CSE 2019 has 2.

How GATE tests Processes, Threads and IPC

More from GATE CSE 2019

Share this solution

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

GateAI solution cardGATE CSE 2019 · Q23 · NAT

Consider three concurrent processes P1, P2 and P3 as shown below, which access a shared variable D that has been initialized to 100. Refer to the table below. The processes are executed on a uniprocessor system running a time-shared operating system. If the minimum and maximum possible values of D after the three processes have completed execution are X and Y respectively, then the value of Y − X is …

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.