GATE / CS ARCHIVE

GATE CSE 2019 / QUESTION 23

Range of outcomes under interleaved updates

Operating Systems · Synchronization & Concurrency · Full GATE CSE 2019 paper

GATE 2019, Q23 1 mark · NAT
Report issue

Synchronization & Concurrency

Question 23, GATE 2019: Shared D starts at 100. Concurrent processes perform P1: D=D+20; P2: D=D−50; P3: D=D+10 on a time-shared uniprocessor. If X and Y are the minimum and maximum possible final values, find Y−X. Use the intended model in which each assignment's read and write can be interleaved with other processes.
Tap to enlarge
Answer & solution

Official answer: 80

Method: split each assignment into a read, local arithmetic, and write; an interrupted process may later overwrite a newer shared value using its earlier read.

1. To attain the minimum, let P2 read 100 and compute 50 but delay its write. Let P1 and P3 complete their increments, then let P2 write its stored 50 last. The final result is 50, because the earlier increments are overwritten.
2. To attain the maximum, let P1 and P2 both read 100. P2 writes 50 first; P1 then writes its stored 120, overwriting the decrement. P3 reads 120 and writes 130. The final result is 130.
3. These are also bounds. Trace the final write back through the value read by its writer, and recursively through preceding writes. This dependency chain starts at 100 and can include each process's change at most once. Its smallest possible sum includes −50 but no positive changes, giving 50; its largest includes +20 and +10 but not −50, giving 130.
4. Both bounds are attainable by steps 1 and 2, so X=50 and Y=130. Their difference is 130−50=80.

Result: 80. If whole assignments were atomic, every order would instead end at 80; the intended model permits preemption within an assignment. Under that different atomic model X=Y=80 and Y−X would be zero. A uniprocessor prevents simultaneous instruction execution but does not by itself make a multi-instruction update atomic.

Original paper, page 8 · Answer key