โ† All CPP Flashcard Decks

Concurrency & Multithreading Flashcards

6 cards from real CPP practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 6 Concurrency & Multithreading flashcards as text
  1. What is the Java Memory Model (JMM) relevant to CPP-level knowledge?

    Answer: It specifies rules about when writes by one thread become visible to other threads

    The JMM defines visibility and ordering guarantees for shared variables across threads, underpinning the behavior of volatile, synchronized, and atomic constructs.

  2. What does the 'volatile' keyword guarantee in Java or C#?

    Answer: Reads and writes to the variable are always directly from/to main memory, ensuring visibility across threads

    Volatile ensures that all threads see the most recent write to the variable by preventing CPU/compiler caching of its value.

  3. What is a thread pool and why is it used?

    Answer: A collection of pre-created threads that execute submitted tasks, avoiding the overhead of creating and destroying threads for each task

    Thread pools reuse a fixed set of worker threads to execute many tasks, reducing the expensive cost of thread creation for short-lived work.

  4. What is the 'happens-before' relationship in concurrent programming?

    Answer: A guarantee that one operation's effects are visible to another operation

    The happens-before relationship guarantees that memory writes visible before a synchronization point are also visible after that point to other threads.

  5. What is the purpose of the 'synchronized' keyword in Java?

    Answer: To ensure only one thread at a time executes the marked method or block

    The synchronized keyword in Java acquires a monitor lock on entry and releases it on exit, ensuring mutual exclusion.

  6. What is async/await and how does it differ from traditional multithreading?

    Answer: async/await enables non-blocking asynchronous code that doesn't require a dedicated thread while waiting for I/O

    async/await pauses execution at await points and resumes when the awaited I/O completes, without blocking a thread during the wait.