Skip to content
Module 7

Concurrency

Write correct, efficient multithreaded C++ — threads, synchronization, atomics, and parallel algorithms.

Threads & Synchronization

  1. std::thread, std::jthread & Thread Management

    Learn to create and manage threads with std::thread and C++20's std::jthread. Understand join vs detach, cooperative cancellation with stop tokens, thread-local storage, and exception handling across thread boundaries.

  2. Mutexes, Locks & Critical Sections

    Master synchronization primitives: mutex, lock_guard, unique_lock, scoped_lock, shared_mutex. Learn to protect shared data, prevent deadlocks, and understand the difference between data races and race conditions.

  3. Condition Variables & Producer-Consumer

    Use condition variables to efficiently coordinate threads. Build a thread-safe producer-consumer queue, handle spurious wakeups, and avoid the lost wakeup problem.

Async, Atomics & Parallelism

  1. std::async, std::future & std::promise

    Use higher-level concurrency abstractions: launch asynchronous tasks with std::async, retrieve results with std::future, and manually set values or exceptions with std::promise.

  2. Atomic Operations & Memory Ordering

    Understand lock-free programming with std::atomic. Master memory orderings (relaxed, acquire, release, seq_cst), implement a spinlock with atomic_flag, and learn the compare-and-swap (CAS) pattern.

  3. Parallel Algorithms & Execution Policies

    Leverage the C++17 parallel STL to parallelize sorting, transformation, and reduction with execution policies. Understand when parallelism helps, Amdahl's law, and practical thread pool design.