C++ Concurrency in Action: Practical Multithreading
by Anthony Williams
ISBN: 9781933988771
Manning Publications Co.

Early Access copies of 2nd edition covering C++17 and the Concurrency TS now available.

C++ Concurrency in Action is the definitive reference and guide to the new C++11 Standard. It is suitable for experienced C++ programmers as well as those who have never written multithreaded code. This book will show you how to write robust multithreaded applications in C++ while avoiding many common pitfalls.

It's not just the best current treatment of C++11's threading facilities ... it's likely to remain the best for some time to come.Scott Meyers

Overview of the 2nd edition

The second edition is being updated to cover C++14, C++17 and the Concurrency TS, along with general improvements throughout the book.

This includes full coverage of the library changes from C++14 and C++17:

  • std::shared_mutex and std::shared_timed_mutex. These provide for multiple-reader/single-writer mutex locks.
  • std::scoped_lock from C++17 for locking multiple mutexes together.
  • Parallel overloads of many standard library algorithms include std::sort, std::for_each and std::transform_reduce.

Plus, full coverage of the library extensions from the concurrency TS:

  • std::experimental::latch to allow waiting for a set number of events to occur
  • std::experimental::barrier and std::experimental::flex_barrier to synchronize groups of threads
  • std::experimental::atomic_shared_ptr to allow atomic accesses to a single shared_ptr instance from multiple threads, as a better alternative that the std::atomic_load and std::atomic_store free functions.
  • Extended futures that allow continuations, so additional functions can be scheduled for when a future is ready.
  • std::experimental::when_all and std::experimental::when_any to allow waiting for either all of a set of futures to be ready, or the first of a set of futures to be ready.

The second edition is currently only available through the Manning Early Access Program. Sign up now to get PDF copies of each chapter as it becomes available, with updates as they are made, and a print copy of the full book when it is complete.

The second edition does of course continue to cover everything from the first edition.

Overview of the first edition

Systems with multiple processors or processors with multiple cores are the norm these days; even many phones have multicore processors. To take advantage of these processor cores you need to use concurrency, either in the form of multiple processors or multiple threads.

With the advent of the C++11 standard, C++ now offers standardized support for multithreaded applications in the form of new library classes and functions and a new multithreading-aware memory model.

C++ Concurrency in Action is about writing programs in C++ using multiple threads for concurrency and the C++ language features and library facilities that make that possible. This book provides a tutorial covering the use of the new C++11 library facilities, such as std::thread, std::future and std::condition_variable, as well as an in-depth description of the new memory model and std::atomic classes for low level synchronization. In later chapters, the book then goes on to cover the design of multithreaded code, including lock-free data structures and thread pools. Finally, there is a chapter on testing and debugging multithreaded applications.

It doesn't stop there though: the appendices include a brief overview of the new language features in C++11 such as variadic templates, lambda functions and rvalue references, as well as a 127 page reference covering every class and function in the C++11 Standard Thread Library.