CS FundamentalsVery hardGATE CS
Two threads run on different cores. Thread 1: `data = 42; ready = 1;` Thread 2: `while (!ready); print(data);` Both variables are plain (non-atomic) ints initialised to 0, and the hardware may reorder stores. What can thread 2 print?
- A. Always 42
- B. Possibly 0, because the store to ready may become visible before the store to data
- C. Nothing, the loop never exits
- D. A random garbage value other than 0 or 42
Correct answer: B. Possibly 0, because the store to ready may become visible before the store to data
Without memory barriers (or atomic release/acquire), weakly ordered CPUs and compilers may reorder the two stores, so thread 2 can see ready = 1 with stale data = 0. A release store and acquire load fix it.
More Operating Systems questions
- How many of these statements about the critical-section problem are correct? 1. Progress means only processes not in their remainder…
- In Lamport's bakery algorithm, why does a process pick a number with number[i] = max(number) + 1 while choosing[i] is true, and break ties…
- A barrier for N threads is implemented with count (protected by mutex) and a semaphore barrier = 0: each thread does lock; count++; if…
- Processes (arrival, burst): P1 (0, 12), P2 (2, 4), P3 (3, 6), P4 (8, 5), P5 (10, 2). Under SRTF, which process waits the longest, and for…
- Processes (arrival, burst): A (0, 5), B (1, 7), C (3, 2), D (4, 6). Round Robin with quantum 4 (new arrivals queued before a preempted…
- Processes (arrival, burst, priority; smaller number = higher priority): P1 (0, 3, 2), P2 (1, 6, 1), P3 (2, 4, 3), P4 (12, 2, 1), P5 (13…