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.

HardTechnical
0 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.
MediumTechnical
0 practiced
In Go, explain differences between using `sync.Mutex` and channel-based ownership for protecting shared maps. Convert a sketch of a concurrent map protected by `sync.Mutex` into an actor-like goroutine that owns the map and processes requests over channels, provide a compact code sketch, and discuss performance and complexity trade-offs.
MediumTechnical
0 practiced
Explain priority inversion and priority inheritance. Provide a practical scenario in a multi-threaded server where a low-priority thread holding a lock causes a high-priority thread to be blocked, and describe two mitigation strategies you could implement at the OS or application level.
MediumTechnical
0 practiced
Explain memory ordering, sequential consistency, acquire-release semantics, and memory barriers in terms an SRE can apply when debugging multi-core production servers. Give a simple example of a visibility bug caused by reordering and the minimal fix using acquire/release or a memory barrier.
MediumTechnical
0 practiced
How can heap and CPU profiling help diagnose synchronization bottlenecks such as hot locks or contention hotspots? Describe the metrics to look for, how to attribute time blocked on locks to call stacks, and name Linux and language-specific tools you would use in production to gather this information with minimal overhead.

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.