Bird
Raised Fist0

You have a mutable shared configuration object causing race conditions in a concurrent system. Which fix uses immutability to solve this?

medium๐Ÿ“ Analysis Q14 of Q15
LLD - Advanced LLD Concepts
You have a mutable shared configuration object causing race conditions in a concurrent system. Which fix uses immutability to solve this?
AAdd locks around every access to the mutable object.
BReplace the shared object with an immutable configuration instance passed by value.
CAllow threads to modify the shared object but reset it periodically.
DUse global variables to store configuration for faster access.
Step-by-Step Solution
Solution:
  1. Step 1: Identify immutability benefit in concurrency

    Immutable objects prevent race conditions by disallowing changes.
  2. Step 2: Choose solution using immutability

    Replacing shared mutable object with immutable instance passed by value avoids conflicts.
  3. Final Answer:

    Replace the shared object with an immutable configuration instance passed by value. -> Option B
  4. Quick Check:

    Immutability fixes race conditions [OK]
Quick Trick: Immutable shared data avoids race conditions [OK]
Common Mistakes:
MISTAKES
  • Relying only on locks without immutability
  • Allowing mutable shared state
  • Using global variables increases risk

Want More Practice?

15+ quiz questions ยท All difficulty levels ยท Free

Free Signup - Practice All Questions
More LLD Quizzes