Bird
0
0

Given a system using a mutex lock for a shared resource, what happens if a thread tries to acquire the lock while it is already held by another thread?

medium📝 Analysis Q5 of 15
LLD - Design — Parking Lot System
Given a system using a mutex lock for a shared resource, what happens if a thread tries to acquire the lock while it is already held by another thread?
AThe thread waits (blocks) until the lock is released
BThe thread acquires the lock immediately
CThe thread throws an error and terminates
DThe thread skips the critical section
Step-by-Step Solution
Solution:
  1. Step 1: Understand mutex lock behavior

    A mutex lock allows only one thread to hold it at a time; others must wait.
  2. Step 2: Determine thread behavior on locked mutex

    If a thread tries to acquire a locked mutex, it blocks until the lock is free.
  3. Final Answer:

    The thread waits (blocks) until the lock is released -> Option A
  4. Quick Check:

    Mutex lock blocks waiting threads = true [OK]
Quick Trick: Mutex blocks threads until lock is free [OK]
Common Mistakes:
MISTAKES
  • Assuming thread acquires lock immediately
  • Thinking thread throws error on lock contention
  • Believing thread skips critical section automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes