CS FundamentalsVery hardGATE CS (PYQ pattern)
Shared integer x = 1. Thread T1 executes x = x + 1; x = x + 1; and thread T2 executes x = x * 2;. Each statement is compiled to a LOAD into a private register followed by a STORE, with no locking, and the threads interleave arbitrarily at the instruction level. Which set is exactly the set of possible final values of x?
- A. {2, 3, 4, 5, 6}
- B. {4, 5, 6}
- C. {2, 3, 4, 6}
- D. {2, 3, 4, 5, 6, 8}
Correct answer: A. {2, 3, 4, 5, 6}
Enumerating all interleavings of the 4 + 2 instructions gives [2, 3, 4, 5, 6]. Atomic statements would give only 4, 5 or 6; lost updates add 2 and 3.
More Operating Systems questions
- Semaphores a = 1, b = 0, c = 0. Four processes each run once: P1: wait(a); print 1; signal(b); signal(c). P2: wait(b); print 2; signal(a)…
- Round Robin with quantum 4 ms. Processes (arrival, burst) in ms: P1 (0, 7), P2 (1, 4), P3 (2, 9), P4 (3, 5), P5 (16, 3). A process that…
- Periodic tasks (execution time, period = deadline): T1 (2, 5), T2 (4, 7). Which statement is correct?
- Three periodic tasks (execution time, period = deadline) are given: A (1, 4), B (2, 6), C (3, 12). Which statement is correct?
- A system has R identical units of one resource. Four processes need at most 3, 4, 2 and 5 units. Each process requests units TWO at a time…
- Banker's algorithm: 5 processes, resource types A, B, C with totals (10, 5, 7). Allocation / Maximum: P0 (0,1,0)/(7,5,3), P1…