Bird
0
0

Why is it important that a Mutex in Ruby is reentrant-safe when used with synchronize?

hard📝 Conceptual Q10 of 15
Ruby - Concurrent Programming
Why is it important that a Mutex in Ruby is reentrant-safe when used with synchronize?
ATo let multiple threads lock the Mutex simultaneously
BTo prevent any thread from ever unlocking the Mutex
CTo automatically unlock the Mutex after each block
DTo allow the same thread to lock the Mutex multiple times without deadlock
Step-by-Step Solution
Solution:
  1. Step 1: Understand reentrancy in Mutex

    Reentrant-safe means the same thread can lock multiple times safely.
  2. Step 2: Identify why this matters with synchronize

    Nested synchronize calls by the same thread won't cause deadlock if Mutex is reentrant-safe.
  3. Final Answer:

    To allow the same thread to lock the Mutex multiple times without deadlock -> Option D
  4. Quick Check:

    Reentrant Mutex = Same thread multiple locks safe [OK]
Quick Trick: Reentrant Mutex avoids deadlock on nested locks by same thread [OK]
Common Mistakes:
  • Thinking multiple threads can lock simultaneously
  • Assuming automatic unlock after block
  • Believing threads cannot unlock Mutex

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes