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
49 practiced
You have an intermittent race that corrupts packet length field occasionally. Propose a debugging and test plan tailored for an embedded target with limited tracing capability. Include lightweight instrumentation to capture time-ordered events, stress test strategies, and ideas for deterministic replay or reproduction on host hardware.
HardTechnical
51 practiced
Provide a code sketch and algorithm for a lock-free reference-counted shared buffer usable by multiple readers and single writer. Explain necessary atomic operations, memory ordering, and how to safely reclaim the buffer when the final reference is released, including corner cases where a reader may still be accessing data during reclamation.
HardTechnical
58 practiced
Design and implement a real-time safe try-lock with timeout for an embedded RTOS. The API should allow immediate try_lock (non-blocking), timed_lock (block up to timeout), and unlock. Discuss how you handle priority inversion, how you measure and bound worst-case blocking time, and how you would implement this efficiently on resource-limited systems.
HardSystem Design
61 practiced
Design the concurrency architecture for a sensor-fusion pipeline on a dual-core MCU: multiple sensor interrupts (accelerometer, gyroscope), DMA transfers, and a fusion algorithm with tight real-time deadlines. Specify how you partition work across cores, how data is handed off (DMA -> ISR -> task), synchronization primitives used, and how you ensure deterministic latency for the fusion step.
EasyTechnical
55 practiced
Analyze the following C snippet and identify potential concurrency issues when both an ISR and the main thread access the shared counter:
c
volatile uint32_t counter;
void SysTick_Handler(void) { counter++; }
int main(void) {
  while(1) {
    if (counter >= 100) { counter = 0; /* process event */ }
  }
}
Explain why this is unsafe and suggest two minimal fixes suitable for a small microcontroller.

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.