Bird
0
0

Which concurrency control mechanism fits best?

hard📝 Trade-off Q15 of 15
LLD - Design — Parking Lot System
You design a system where multiple threads read and write a shared cache. To improve performance, you want to allow multiple readers but only one writer at a time. Which concurrency control mechanism fits best?
AUse a read-write lock allowing concurrent reads but exclusive writes
BUse a simple mutex lock for all access
CUse no locks and rely on thread scheduling
DUse a semaphore with count 1 for all operations
Step-by-Step Solution
Solution:
  1. Step 1: Understand concurrency needs for readers and writers

    Multiple readers can safely access shared data simultaneously, but writers need exclusive access to avoid conflicts.
  2. Step 2: Choose appropriate lock type

    A read-write lock allows many readers at once but only one writer, balancing concurrency and safety efficiently.
  3. Final Answer:

    Use a read-write lock allowing concurrent reads but exclusive writes -> Option A
  4. Quick Check:

    Read-write lock fits multiple readers, single writer = B [OK]
Quick Trick: Read-write locks allow many readers, one writer [OK]
Common Mistakes:
MISTAKES
  • Using simple mutex reduces concurrency
  • Ignoring need for exclusive write access
  • Relying on no locks causes data races

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes