CS FundamentalsHardGATE CS
Shared int x = 1. Thread T1 executes `x = x * 2;` and T2 executes `x = x + 3;` concurrently with no locking (each is load, compute, store). How many DISTINCT final values of x are possible?
- A. 4
- B. 2
- C. 3
- D. 1
Correct answer: A. 4
Serial orders give (1×2)+3 = 5 and (1+3)×2 = 8; lost updates give 2 (T2's store overwritten) or 4 (T1's store overwritten). Possible values: [2, 4, 5, 8].
More Operating Systems questions
- Which property does Peterson's algorithm guarantee for two processes, assuming loads and stores are atomic and NOT reordered?
- A test-and-set spinlock: while (TestAndSet(&lock)); / CS / lock = false;. Which requirement of the critical-section problem does it NOT…
- A semaphore S is initialised to 3. The operations wait(S) ×6, signal(S) ×2, wait(S) ×1 are issued in that order by different processes…
- Binary semaphore mutex = 1 protects a counter. A programmer mistakenly writes signal(mutex); / critical section / wait(mutex); in every…
- In the dining philosophers problem with 5 philosophers, each picks up the LEFT fork and then the RIGHT fork. Which change by itself…
- Readers–writers with readers' preference: semaphores mutex = 1 (protects readcount), wrt = 1. Reader: wait(mutex); readcount++; if…