ReviseAlgo Logo

Concurrency

10 Topics
1

std::thread

Create and manage system threads using std::thread and modern std::jthread (C++20).

Dangers of joinable thread destruction, parameter passing safety (dangling references), and std::jthread automatic lifetime management.
2

Mutexes

Synchronize shared resources using std::mutex, recursive_mutex, shared_mutex, and RAII scope locks.

Preventing data races, comparing unique_lock vs lock_guard, and using shared_mutex for reader-writer optimizations.
3

Condition Variables

Coordinate threads using std::condition_variable to wait for state changes without active busy-waiting.

Mechanics of spurious wakeups, why a predicate lambda is required, and unique_lock association.
4

Atomic Operations

Write lock-free concurrent code using std::atomic and compare-and-swap (CAS) primitives.

Lock-free checks, CPU instruction level atomicity, and compare_exchange weak vs. strong.
5

Futures and Promises

Transmit values or exceptions asynchronously between producer and consumer threads using std::promise and std::future.

Unidirectional thread channels, exception propagation across boundaries, and future::get() lifecycle rules.
6

std::async

Launch asynchronous tasks using std::async, understand policies, and avoid the temporary future destructor trap.

Differences between launch policies, and why omitting the return future forces synchronous execution.
7

Thread Pools

Build a thread pool using worker loops, task queues, and condition variables to optimize resource usage.

Why thread creation is slow, how thread pools optimize resource usage, and implementing task queues.
8

Deadlock Prevention

Identify Coffman deadlock conditions and resolve lock contention issues using std::scoped_lock.

Understanding Coffman conditions, locking order rules, and using std::scoped_lock for multi-mutex synchronization.
9

Memory Ordering

Understand the C++ memory model, instruction reordering, and atomic synchronization modes.

Compiler/CPU instruction reordering, sequential consistency costs, and acquire-release synchronization semantics.
10

Coroutines (C++20)

Build stackless asynchronous generators and tasks using co_await, co_yield, and promise structures in C++20.

How coroutines manage state without a stack, and the roles of promise_type and coroutine_handle.