Bird
Raised Fist0

When a vehicle arrives and the parking lot system uses a Singleton ParkingLot instance managing multiple levels, what happens if multiple threads simultaneously request parking spots without synchronization?

easy🧠🧾 Concept Trace Q3 of Q15
OOP & Design Patterns - Design a Parking Lot - LLD with OOP (Classes, Patterns, Extensibility)
When a vehicle arrives and the parking lot system uses a Singleton ParkingLot instance managing multiple levels, what happens if multiple threads simultaneously request parking spots without synchronization?
AEach thread gets a unique ParkingLot instance, avoiding conflicts
BThe Singleton pattern automatically queues requests to prevent conflicts
CRace conditions may occur, causing inconsistent spot allocation
DThe system throws an exception due to concurrent access
Step-by-Step Solution
Solution:
  1. Step 1: Recall Singleton pattern behavior

    Singleton ensures one instance but does not inherently provide thread safety.
  2. Step 2: Consider concurrent access without synchronization

    Multiple threads accessing shared state can cause race conditions.
  3. Step 3: Evaluate options

    Singleton does not create multiple instances (A is wrong), nor does it queue requests automatically (C is wrong), and concurrent access does not necessarily throw exceptions (D is wrong).
  4. Final Answer:

    Option C -> Option C
  5. Quick Check:

    Singleton alone doesn't prevent race conditions [OK]
Quick Trick: Singleton isn't thread-safe by default [OK]
Common Mistakes:
MISTAKES
  • Assuming Singleton prevents all concurrency issues
  • Believing Singleton queues requests automatically
  • Thinking concurrent access always throws exceptions
Trap Explanation:
PITFALL
  • Candidates often overestimate Singleton's thread safety, missing the need for explicit synchronization.
Interviewer Note:
CONTEXT
  • Tests understanding of concurrency implications in design patterns.
Master "Design a Parking Lot - LLD with OOP (Classes, Patterns, Extensibility)" in OOP & Design Patterns

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes