Bird
Raised Fist0

Consider a multithreaded program where one thread modifies a shared variable without synchronization. What is the most likely outcome when the CPU switches between threads?

medium🧠🧾 Concept Trace Q4 of Q15
Operating Systems - Process vs Thread - Key Differences
Consider a multithreaded program where one thread modifies a shared variable without synchronization. What is the most likely outcome when the CPU switches between threads?
AThe shared variable remains consistent because threads share memory.
BThe shared variable may become inconsistent due to race conditions.
CThe CPU prevents inconsistent states by automatically locking shared variables.
DEach thread has its own copy of the shared variable, so no inconsistency occurs.
Step-by-Step Solution
Solution:
  1. Step 1: Understand shared memory in threads

    Threads share the same memory, so variables are accessible by all threads.
  2. Step 2: Analyze unsynchronized access

    Without synchronization, concurrent writes can cause race conditions and inconsistent values.
  3. Step 3: Evaluate options

    The shared variable may become inconsistent due to race conditions correctly identifies the risk of inconsistency due to race conditions.
  4. Final Answer:

    Option B -> Option B
  5. Quick Check:

    Unsynchronized shared access causes race conditions [OK]
Quick Trick: Unsynchronized shared variables cause race conditions [OK]
Common Mistakes:
MISTAKES
  • Assuming CPU automatically locks shared variables
  • Believing each thread has separate copies of variables
Trap Explanation:
PITFALL
  • Candidates often think shared memory guarantees consistency without locks.
Interviewer Note:
CONTEXT
  • Checks understanding of thread memory sharing and synchronization necessity.
Master "Process vs Thread - Key Differences" in Operating Systems

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Operating Systems Quizzes