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
54 practiced

Implement a single-producer single-consumer ring buffer without locks. How do you tell full from empty, and which memory-ordering guarantees make it correct on weakly ordered hardware?

EasyTechnical
67 practiced

What does a memory barrier do, and why is volatile not a substitute for atomics or locks? Give a case where volatile is needed and a case where it is not enough.

EasyTechnical
68 practiced

What is compare-and-swap? Explain how a retry loop built on it works, and what problems such loops have.

HardSystem Design
57 practiced

Design a mutex that supports priority inheritance. What state does it keep, how do acquire and release work, and how do you handle nested locks and bound the priority adjustments?

HardTechnical
102 practiced

Design a bounded lock-free multi-producer multi-consumer ring queue in C that uses no dynamic allocation and only 32-bit atomic operations. How do per-slot sequence numbers let producers and consumers claim slots, how do you tell full from empty, and what ordering and ABA considerations apply on a weakly ordered core such as Cortex-M?

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.