4.2.8Operating Systems
Thread synchronization needs — shared memory issues
1,843 words8 min readdifficulty · medium3 backlinks
WHY do shared-memory issues even arise?
WHY this is dangerous: the CPU does not execute a high-level line like count++
atomically. The OS scheduler can preempt a thread at any machine instruction boundary.
WHAT goes wrong (the core problem): a race condition — the final result depends on the timing/order of thread execution, not just the inputs.
HOW a single count++ breaks — derive it from instructions
count++ is really three machine steps. Let me derive the failure from scratch.