Module 08 of 10

Concurrency

Lessons

About This Module

Concurrency lets a program do more than one thing at a time. This module starts with threads: how to start a function on a new std::thread, wait for it with join, and the different ways to create threads in C++11.

It then covers what goes wrong when threads share data. A race condition happens when two threads change the same value at the same time, and a mutex protects that shared data so only one thread uses it at once. The last lesson shows std::async, an easier way to run work in parallel and collect the result.

Watch the lessons in order, then continue on to Build Systems & Debugging.

Lessons

4 videos
01

Threads in C++

How to run a function on a separate thread with std::thread and wait for it to finish with join.

02

How To Create Threads In C++

The different ways to create a thread in C++11: function pointers, lambdas, functors and member functions.

03

Race Condition and Mutex in C++

What a race condition is, why it breaks programs that share data between threads, and how a mutex fixes it with a worked example.

04

How to Make C++ Run Faster (with std::async)

Using std::async and futures to spread work across CPU cores, and what to watch for when threads share results.