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.

EasyTechnical
91 practiced

Two threads each run counter += 1 on a shared integer many times, and the final total is sometimes too low. Explain exactly how the interleaving loses updates, and show how you would fix it. When would you choose a lock and when an atomic?

EasyTechnical
90 practiced

What is the difference between a race condition and a data race? Give a small example of each, and explain why code can be free of data races and still contain a race condition.

MediumSystem Design
52 practiced

Design a thread-safe publish-subscribe event bus where events are posted from any thread and delivered on a designated thread. How do you allow subscribe and unsubscribe during dispatch without deadlock or missed events?

EasyTechnical
55 practiced

How can thread confinement and message passing help you avoid locks? Give an example of confining state to one thread or queue, and say when you would still need synchronization.

HardTechnical
64 practiced

A concurrency bug disappears when you add logging, or only occurs in release builds on one device. Why does that happen, and how do you still reproduce it deterministically?

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.