InterviewStack.io LogoInterviewStack.io

Concurrency and Synchronization Questions

Covers the principles and practical techniques for safely coordinating concurrent execution and access to shared resources. Topics include models of concurrency such as threads, processes, interrupt handlers, and tasks in a real time operating system; differences between preemptive and cooperative scheduling; shared data hazards including race conditions and read modify write hazards; critical sections and approaches to protect them including disabling interrupts in embedded contexts and scoped locks. Synchronization primitives and patterns are included: mutexes, binary semaphores, counting semaphores, condition variables, message queues, atomic operations and lock free primitives such as compare and swap. Memory ordering concerns and memory barrier usage on multi core systems are covered, along with priority inversion and priority inheritance. Also addressed are deadlock, livelock, and starvation concepts and avoidance strategies, granularity and performance trade offs of locking, and practical synchronization patterns. Preparation should include identifying and fixing races in code, designing correct concurrent interfaces, and debugging and testing techniques such as stress testing, instrumentation, deterministic replay, race detectors, static analysis, and code review strategies.

MediumTechnical
53 practiced
In an embedded or kernel context, one common primitive is to disable interrupts to protect a short critical section. Describe the implications of disabling interrupts on latency and interrupt handling. Provide example pseudocode showing when disabling interrupts is appropriate and list three rules you would apply to keep the system responsive.
MediumTechnical
48 practiced
Implement a concurrent stack using a lock-free algorithm in Java using `AtomicReference<Node>` for the head pointer. Provide code sketches for `push()` and `pop()` using CAS loops, and describe correctness concerns and how Java's garbage collector interacts with this implementation.
MediumTechnical
91 practiced
A shared hash table in production uses a single global lock and experiences heavy contention. Propose a set of strategies to reduce contention and describe trade-offs for each: (a) fine-grained locking/sharding, (b) read-write locks, (c) lock-free data structures, (d) optimistic concurrency/versioning.
HardTechnical
67 practiced
Given the C++11 example where thread A does `x.store(42, std::memory_order_relaxed); y.store(1, std::memory_order_relaxed);` and thread B does `if (y.load(std::memory_order_relaxed)==1) print(x.load(std::memory_order_relaxed));`, explain how reordering could cause B to print a stale or zero value. Show the minimal corrected code using `memory_order_release` and `memory_order_acquire` and explain why it is sufficient.
HardTechnical
49 practiced
Implement a lock-free bounded single-producer single-consumer (SPSC) queue in C or C++ using atomics for head and tail indices and a fixed-size ring buffer. Provide pseudocode for `enqueue()` and `dequeue()` and explain the required memory-ordering semantics to ensure correctness on weakly-ordered architectures.

Unlock Full Question Bank

Get access to hundreds of Concurrency and Synchronization interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.