Multithreading, Locks, Concurrency Hazards, and a Bounded Queue Design
Context: Technical screen for a software engineering role. You are asked to demonstrate understanding of multithreading primitives, concurrency pitfalls, and to implement a thread-safe bounded queue supporting multiple producers and consumers using condition variables.
Tasks
-
Explain how multithreading works and when to use locks.
-
Compare mutexes, semaphores, and read–write locks: pros/cons and appropriate use cases.
-
Identify race conditions, deadlocks, livelocks, and starvation; outline concrete avoidance strategies (e.g., lock ordering, timeouts, backoff, minimizing critical sections).
-
Design and implement a thread-safe bounded queue (multiple producers and consumers) using condition variables.
-
Describe how you would test it for correctness and performance.