CS FundamentalsVery hardGATE CS · Advanced
Two threads share an integer x initialised to 0. Thread 1 executes the loop body x = x + 1 three times; Thread 2 executes it twice. Each execution of the body compiles to three separate steps: load x into a private register, add 1 to the register, store the register back into x. With arbitrary interleavings of these steps, what is the smallest final value of x that can occur?
- A. 5
- B. 1
- C. 2
- D. 3
Correct answer: C. 2
Lost updates can wipe out almost all work: the minimum is 2. Thread 1 loads 0 and pauses; thread 2 completes one iteration (x = 1); thread 1 stores 1; thread 2 loads 1 and pauses; thread 1 finishes its other two iterations (x = 3); thread 2 stores 2. All reachable finals: [2, 3, 4, 5].
More Operating Systems questions
- Four periodic tasks (computation time C, period T = relative deadline), all released at t = 0, are scheduled by preemptive rate-monotonic…
- A disk spins at 7200 rpm with 500 sectors per track and an average seek time of 5 ms. The controller adds 0.2 ms of overhead. What is the…
- A stride scheduler gives processes A, B and C 100, 50 and 250 tickets respectively, with stride = 10000 / tickets. Every process starts…
- A process uses 100 MiB of memory. A page-table entry is 8 bytes, and on average half of the last page is wasted. Among page sizes that are…
- The aging algorithm keeps an 8-bit counter per page for pages 0-3. At the end of every clock tick each counter is shifted right by one bit…
- A file system has 1 KB blocks and 4-byte block pointers; the inode (already in memory) holds 12 direct pointers and one single-, one…