Skip to content
GATEiit

GATE CSE 2019 Q33: Race on shared D = 100 with D+20, D−50, D+10: max minus min final value

Syllabus topic: Inter-process communication, concurrency and synchronization

Question

Consider three concurrent processes P1, P2 and P3 as shown below, which access a shared variable D that has been initialized to 100.

P1P2P3
⋮⋮⋮
D = D + 20D = D − 50D = D + 10
⋮⋮⋮

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 _____________.

Try it: numerical answer: type the value

Numerical answer. No negative marking.
Show answer and explanation

Answer: 80 (official GATE 2019 final answer key)

Concept used: Race condition: each update is a read-modify-write, so an interleaving can lose other processes' updates.

Concept notes

Loading notes…

First step: For the maximum, let P2 read D first but write before the others write their results; for the minimum, arrange for P2's write to be the last one, overwriting the additions.

Full step-by-step solution

Loading…

Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.

More questions on Inter-process communication, concurrency and synchronization

Every PYQ on this topic →

Share this question

WhatsAppDownload image

Source: official GATE 2019 CS question paper and final answer key, organised by IIT Madras. Question paper · Answer key