Bird
0
0

Which of these best describes what happens if two threads try to lock the same Mutex at the same time?

easy📝 Conceptual Q2 of 15
Ruby - Concurrent Programming
Which of these best describes what happens if two threads try to lock the same Mutex at the same time?
ABoth threads lock it simultaneously
BOne thread locks it, the other waits until it is unlocked
CThe Mutex throws an error
DThe second thread skips the lock and continues
Step-by-Step Solution
Solution:
  1. Step 1: Understand Mutex locking behavior

    Mutex allows only one thread to hold the lock at a time.
  2. Step 2: Determine what happens to the second thread

    The second thread waits until the first thread unlocks the Mutex.
  3. Final Answer:

    One thread locks it, the other waits until it is unlocked -> Option B
  4. Quick Check:

    Mutex lock = One thread at a time [OK]
Quick Trick: Only one thread can hold a Mutex lock at once [OK]
Common Mistakes:
  • Assuming simultaneous locks are possible
  • Expecting an error on contention
  • Thinking threads skip locking

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes