Concurrent Thinking in C++ [2017 class archive]

“Concurrent Thinking in C++” is a two-day training course taught by Anthony Williams of Just Software Solutions. It is offered at the Meydenbauer Conference Center from 9AM to 5PM on Saturday and Sunday, September 23rd and 24th, 2017 (immediately prior to the conference). Lunch is included.

Course Description

One of the most difficult issues around designing software with multiple threads of execution is synchronizing data.

Whether you use actors, active objects, futures and continuations or mutable shared state, every non-trivial system with multiple threads needs to transfer data between them. This means thinking about which data needs to be processed by which thread, and ensuring that the right data gets to the right threads in the right order. It also means thinking about API design to avoid race conditions.

In this workshop you will encounter a series of scenarios involving multithreaded code, and be guided through identifying the problem areas and the ways of handling them.

You will learn techniques for thinking about the scenarios to ease the analysis, as well as details of the tools we have available in C++ to mitigate the problems. You will also learn how to use the C++ standard library to help enforce the requirements of each scenario in code.

Prerequisites

Students are expected to have a good knowledge of C++, but no prior knowledge of concurrency or multithreading is assumed.

Students will require a laptop with one of the following compilers to handle the example code:

  • Microsoft Visual Studio 2015 or later.
  • gcc 4.9 or later
  • clang 3.4 or later with libc++ 3.5 or later

Course Topics

  • The C++ memory model and happens-before

We will look at the ordering guarantees provided by various constructs, and how we can use them to provide synchronization between threads.

  • Race conditions and data races

We will look at the difference between a generic race condition and a data race, identifying race conditions, and avoiding them.

  • Mutexes and condition variables

Using mutexes to protect data, and avoiding the common pitfalls with condition variable usage.

  • Futures and promises

Using futures to synchronize actions, and pass data between threads.

  • Atomic operations and lock-free code

Lock-free code isn’t just about avoiding mutexes. We will look at correctly synchronizing concurrent actions with atomic operations.

  • Designing APIs for concurrent usage

There’s more to supporting concurrent usage of an API than merely wrapping the body of each function in a lock. We will look at race conditions inherent in some API designs, and how to avoid them in our own code.

Course Instructor

AnthonyWilliams.cropped

Anthony Williams is the author of C++ Concurrency in Action, and a UK-based developer and consultant with many years of experience in C++. He has been an active member of the BSI C++ Standards Panel since 2001, and is author or coauthor of many of the C++ Standards Committee papers that led up to the inclusion of the thread library in the C++11 Standard. He is the developer of the just::thread implementation of the C++11 thread library from Just Software Solutions Ltd. Anthony lives in the far west of Cornwall, England.