Concurrency, Synchronization & Deadlock Questions

Correctness of shared-state coordination between concurrent threads and tasks. Covers mutexes (futex-based and spin-then-sleep), semaphores, condition variables, spinlocks, reader-writer locks, and the producer-consumer pattern; atomic operations, compare-and-swap, lock-free and wait-free structures with the ABA problem and safe memory reclamation; memory ordering, barriers and acquire/release semantics; race conditions, data races, critical sections, time-of-check to time-of-use gaps and read-modify-write hazards; deadlock (the Coffman conditions, lock ordering, prevention and detection), livelock and starvation; priority inversion as a locking hazard and the priority-inheritance fix; designing thread-safe structures such as bounded queues, caches, rate limiters, event buses and work-stealing schedulers, with coarse versus fine-grained and per-key locking; alternatives to locking such as thread confinement, message passing, actors and transactional memory; and diagnosing and testing concurrency bugs (heisenbugs, race detectors, stress and replay, reviewing concurrent code). Excludes a specific language's threading API and memory model, concurrency for throughput and pool tuning, distributed locks and consensus, database isolation levels, RTOS ceiling protocols and schedulability, and interrupt masking between ISRs and main code.

MediumTechnical
53 practiced

Show a minimal example in code where two threads acquire two locks in opposite order and deadlock. Then fix it, and explain how you would detect and reproduce this in a live system.

HardTechnical
58 practiced

Describe a lock-free multi-producer multi-consumer queue (for example the Michael-Scott design). How do operations help each other, what is the linearization point, and how are ABA and memory reclamation handled?

EasyTechnical
63 practiced

Describe the purpose of a mutex, a semaphore, a condition variable and a barrier. For each, give one realistic use and one situation where it is the wrong tool.

EasyTechnical
57 practiced

What is a counting semaphore? Describe wait and signal, how it differs from a binary semaphore, and a realistic use such as limiting concurrent access to a scarce resource. What goes wrong with fairness or misuse?

HardTechnical
58 practiced

Design a thread-safe LRU cache with concurrent get and put. Describe your data structures, locking strategy and eviction, and explain how you avoid one global lock becoming a bottleneck.

Unlock Full Question Bank

Get access to all Concurrency, Synchronization & Deadlock interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.