Concurrency

0%
Theory
Quiz

    Foundations & Models

    • Can you explain the conceptual difference between concurrency and parallelism? Can a single-core machine achieve both?

      Junior
    • Can you walk through the typical lifecycle and states of a thread, from creation to termination?

      Junior
    • Explain the difference between a thread and a process in terms of memory isolation and communication overhead. Why are threads often preferred for high-performance concurrency?

      Junior
    • How does introducing concurrency typically affect a system's throughput versus its latency? When might adding more threads actually decrease performance?

      Senior
    • What are the primary overhead costs associated with multi-threading?

      Mid
    • What is a context switch, and why is it computationally expensive? How do lightweight concurrency models like coroutines mitigate this cost?

      Mid
    • What is the difference between Cooperative and Preemptive multitasking?

      Mid
    • What is the difference between CPU-bound and I/O-bound tasks, and how does that change your choice of concurrency model?

      Junior
    • What is thread oversubscription, and how does having more runnable threads than cores affect performance?

      Mid
    • Why does concurrency often lead to non-deterministic behavior in a program?

      Junior

    Concurrency Patterns

    • Compare the 'Shared Memory' model with the 'Message Passing' (CSP) model. What are the trade-offs?

      Mid
    • Describe the producer-consumer problem. Why is a bounded buffer usually preferred over an unbounded one in production systems?

      Mid
    • In Go-style concurrency (CSP), why is it said to 'Share memory by communicating, not communicate by sharing memory'?

      Mid
    • What are the core principles of the Actor Model? How does it handle state isolation and fault tolerance?

      Senior
    • What are the guarded-suspension and balking patterns, and when would you use each?

      Senior
    • What is 'structured concurrency'? How does it improve the management of task lifetimes and error propagation compared to 'fire-and-forget' threads?

      Senior
    • What is a blocking queue, and why is it a natural fit for the producer-consumer pattern?

      Junior
    • What is the 'Producer-Consumer' problem, and what synchronization primitives are typically used to solve it?

      Junior

    Async & Event Driven Io

    • Conceptually, what is the C10K problem, and how did the shift from 'thread-per-connection' to 'event-driven' architectures solve it?

      Senior
    • Explain how a single-threaded event loop can handle thousands of concurrent I/O requests without threads.

      Mid
    • Explain the 'Async/Await' model. What happens to the underlying thread when an await point is reached?

      Mid
    • How can futures/promises be composed and chained, and how does error propagation work through such a chain?

      Mid
    • How is cancellation and timeout handling coordinated in asynchronous or task-based code, and why is cooperative cancellation preferred over forceful termination?

      Senior
    • What are the Reactor and Proactor patterns, and how do they differ in handling I/O readiness versus completion?

      Senior
    • What happens under the hood when a program encounters an await keyword, and how is the execution state preserved?

      Senior
    • What is 'callback hell,' and how do futures/promises or async/await address it?

      Junior
    • What is Backpressure, and why is it critical in concurrent data pipelines?

      Mid
    • What is the 'GIL' (Global Interpreter Lock) in languages like Python or Ruby, and how does it impact multi-core utilization?

      Mid
    • What is the conceptual difference between a Future and a Promise? How do they help manage the 'callback hell' problem?

      Mid
    • What is the difference between blocking and non-blocking I/O, and how does non-blocking I/O let a small number of threads serve many connections?

      Mid
    • When would you prefer an Asynchronous (Event-Loop) model over a Multithreaded model?

      Mid

    Memory Model & Visibility

    • Concurrency correctness is often framed around three concerns: atomicity, visibility, and ordering. Can you explain what each one means?

      Mid
    • Explain the double-checked locking pattern. Why is the volatile keyword necessary for this pattern to be thread-safe in modern memory models?

      Senior
    • In the context of a language memory model, what does the 'happens-before' relationship guarantee? Why is it critical for visibility?

      Senior
    • What is a 'Memory Barrier' (or Fence), and what is the difference between Acquire and Release semantics?

      Senior
    • What is a memory barrier, and how does it enforce ordering between different threads?

      Senior
    • What is a Memory Model (e.g., JMM or C++11 model), and why do we need one?

      Senior
    • What is safe publication of an object, and why can sharing a reference across threads without proper synchronization expose a partially constructed object?

      Senior
    • What is sequential consistency as a memory model guarantee, and why don't most real systems provide it by default?

      Senior
    • What is the difference between marking a variable as volatile versus using an Atomic type? Does volatile guarantee atomicity for increment operations?

      Mid
    • What is the difference between Sequential Consistency and Eventual Consistency in a multi-threaded program?

      Senior
    • What is the volatile keyword's effect on visibility and instruction reordering?

      Mid
    • Why do compilers and CPUs reorder instructions, and how can this break concurrent code that looks correct on paper?

      Senior

    Locks & Synchronization Primitives

    • Explain the 'Readers-Writers' problem. Why would you use a Read-Write Lock instead of a standard Mutex?

      Mid
    • Explain the Condition Variable and why you must always call wait() inside a loop.

      Mid
    • Explain the Readers-Writers problem. What are the trade-offs between a 'read-preferring' and a 'write-preferring' implementation?

      Senior
    • How would you coordinate a Producer-Consumer relationship using only a Mutex and a Condition Variable? Why must the 'wait' call always be inside a loop?

      Mid
    • What is 'Lock Striping' (or Lock Splitting), and how does it improve the scalability of a concurrent data structure?

      Senior
    • What is a 'Reentrant Lock' (or Recursive Lock), and what problem does it solve?

      Mid
    • What is a barrier (or a CountDownLatch/phaser), and how does it differ from a lock as a synchronization tool?

      Mid
    • What is a monitor, and how does it combine mutual exclusion with condition-based waiting?

      Mid
    • What is a Spinlock, and in what specific scenario is it more efficient than a blocking Mutex?

      Mid
    • What is a spurious wakeup, and how should code handle it?

      Mid
    • What is a try-lock (or timed lock), and how can it be used to avoid deadlock?

      Mid
    • What is the difference between coarse-grained and fine-grained locking? How does 'lock striping' help improve the scalability of a concurrent data structure?

      Senior
    • What is the difference between Optimistic and Pessimistic Locking? When would you prefer one over the other?

      Mid
    • What is the fundamental difference between a mutex and a semaphore? In what scenario would you use a counting semaphore instead of a binary mutex?

      Junior
    • When would you prefer a ReadWriteLock over a standard reentrant lock, and what is the risk of writer starvation in this model?

      Mid
    • Why can Lock Contention lead to poor CPU utilization even when you have many cores?

      Senior

    Lock Free & Atomics

    • Explain the ABA problem in lock-free data structures, and how do tagged pointers or hazard pointers solve it?

      Senior
    • How does the CAS (Compare-and-Swap) operation work? Why is it considered the building block of lock-free programming?

      Senior
    • What are the differences between test-and-set, fetch-and-add, and compare-and-swap as atomic primitives?

      Senior
    • What is Read-Copy-Update (RCU), and in what read-heavy scenarios is it beneficial?

      Senior
    • What is the difference between Lock-free, Wait-free, and Obstruction-free algorithms?

      Senior
    • Why are lock-free data structures often more performant under high contention than lock-based ones?

      Senior
    • Why can a striped atomic accumulator (like a LongAdder) outperform a single atomic counter under high contention?

      Senior
    • Why is designing correct lock-free data structures so difficult compared to using locks?

      Senior
    • Why is it generally harder to implement a lock-free Queue than a lock-free Stack?

      Senior

    Shared State & Thread Safety

    • Explain the Check-Then-Act race condition.

      Junior
    • Explain the Copy-On-Write strategy and its benefits/drawbacks in a concurrent environment.

      Senior
    • How do you categorize classes by thread-safety, immutable, thread-safe, conditionally thread-safe, and thread-hostile?

      Senior
    • How would you approach designing a thread-safe class: what strategies exist for encapsulating and protecting mutable state?

      Senior
    • How would you implement thread-safe lazy initialization, and what are the pitfalls?

      Mid
    • What are the risks of using ThreadLocal variables in a thread-pooled environment?

      Senior
    • What does it mean for a class to be 'Thread-Safe'? Does using thread-safe collections make your entire application thread-safe?

      Mid
    • What does it mean for a function to be Reentrant? Is every thread-safe function reentrant?

      Senior
    • What is a benign race condition, and how does it differ from a harmful one?

      Senior
    • What is the difference between synchronized/wrapper collections and truly concurrent collection implementations?

      Mid
    • What is the read-modify-write problem, and why do operations like incrementing a counter require synchronization?

      Junior
    • What is the technical distinction between a race condition and a data race, and can you have one without the other?

      Senior
    • What is thread confinement, how do ThreadLocal variables help achieve it, and what are the risks of using them in a thread-pooled environment?

      Mid
    • Why is immutability such a powerful tool for concurrency, and are there performance trade-offs to using copy-on-write strategies?

      Mid
    • Why is shared mutable state the fundamental source of difficulty in concurrent programming, and what design strategies minimize it?

      Junior

    Deadlock Livelock & Contention

    • Explain the difference between livelock and starvation, and how can a fair locking strategy help prevent starvation?

      Mid
    • Explain the Dining Philosophers problem. What does it illustrate about deadlock, and how can it be solved?

      Mid
    • How do you detect a deadlock in a running application?

      Mid
    • How do you distinguish between Deadlock, Livelock, and Starvation?

      Mid
    • How do you identify lock contention in a running application, and what are three strategies to reduce it?

      Senior
    • How do you prevent Deadlock in a system that requires acquiring multiple locks?

      Mid
    • What are the four Coffman conditions required for a deadlock to occur, and how can you prevent deadlock by breaking one of these conditions?

      Mid
    • What is a lock convoy, and what conditions cause one to form?

      Senior
    • What is priority inversion, and how can a 'priority inheritance' protocol solve it?

      Senior
    • What is the difference between deadlock prevention, avoidance, and detection from a programmer's perspective?

      Senior

    Thread Pools & Lightweight Threads

    • Explain the work-stealing algorithm. How does it improve resource utilization compared to a simple work-sharing approach?

      Senior
    • How does a thread pool work, and what factors should you consider when deciding the optimal number of threads for a pool for CPU-bound vs I/O-bound work?

      Mid
    • What are coroutines and continuations, and how do they enable lightweight cooperative concurrency?

      Mid
    • What are virtual (or green) threads, and how do they differ from traditional OS/platform threads? Why are they particularly useful for I/O-bound tasks?

      Mid
    • What is 'Thread Pinning' in the context of virtual threads, and why is it a performance concern?

      Senior
    • What is M:N (many-to-many) threading, where many user-mode threads are multiplexed onto fewer OS threads, and what advantages does it give a runtime?

      Senior
    • Why do we use thread pools instead of creating a new thread for every task? What are the risks of a thread pool that is too small versus one that is too large?

      Mid

    Parallelism & Decomposition

    • How do you decompose a problem for parallel execution, and how does task granularity affect the outcome?

      Mid
    • How does the map-reduce pattern express parallelism, and what kinds of problems fit it?

      Mid
    • What does it mean for a workload to be 'embarrassingly parallel,' and why do such problems scale so well?

      Junior
    • What is pipeline (dataflow) parallelism, and when is it a good decomposition strategy?

      Mid
    • What is the difference between task parallelism and data parallelism? Give an example of a workload suited for each.

      Mid

    Performance Scalability & Testing

    • What is 'false sharing' at the CPU cache level, and how can a programmer structure their data to avoid it?

      Senior
    • What is Amdahl's Law, and how does it help you determine the maximum theoretical speedup of a program when adding more CPU cores?

      Mid
    • What is Gustafson's Law, and how does it offer a more optimistic view of parallel scalability than Amdahl's Law?

      Senior
    • What is the difference between Strong Scaling and Weak Scaling?

      Senior
    • Why is it difficult to test concurrent code, and how would you reproduce a heisenbug that only occurs occasionally in production?

      Senior