Advanced level · Module 5 of 6 · 22 guided hours
Concurrency in Modern C++
Run work in parallel with threads, protect shared data with mutexes and atomics, and use futures and parallel algorithms safely.
Learning objectives
- Start and join threads safely with std::jthread
- Protect shared data and avoid races and deadlocks
- Use futures and parallel algorithms for task parallelism
Topics
- std::thread and std::jthread
- data races
- std::mutex and std::scoped_lock
- deadlock
- std::atomic
- std::async and futures
- parallel algorithms
Lessons
-
Lesson 1 Threads and Data Races
Start threads with std::jthread and see how unsynchronised access to shared data produces data races.
std::thread / std::jthreadjoindata raceThreadSanitizer
-
Lesson 2 Mutexes, Locks and Deadlocks
Protect shared data with mutexes and RAII locks, and avoid deadlocks.
std::mutexstd::lock_guard / std::scoped_lockcritical sectiondeadlock
-
Lesson 3 Atomics, Futures and Tasks
Use atomics for simple shared counters and std::async with futures to run tasks that return results.
std::atomicstd::asyncstd::futuretask-based parallelism
-
Lesson 4 Parallel Algorithms and Measuring Speed-up
Use the standard parallel execution policies, and measure and explain the speed-up you achieve.
std::execution::parspeed-upAmdahl's lawthread overhead
Practical activity
Process sensor files in parallel, one task per file, combining the results without shared mutable state, and verify the results match the sequential version.
Expected outcomes
- Correct concurrent code
- Measured parallel speed-ups
Assessment
Practical marked by identical sequential/parallel results, a clean ThreadSanitizer run and a measured speed-up.
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.