Concurrency with Modern C++
Concurrency with Modern C++
Minimum price
Suggested price
Concurrency with Modern C++

This book is 100% complete

Completed on 2018-11-18

About the Book

Concurrency with Modern C++ is a journey through current and upcoming concurrency in C++.

  • C++11 and C++14 have the basic building blocks for creating concurrent or parallel programs.
  • With C++17 we got the parallel algorithms of the Standard Template Library (STL). That means, most of the algorithms of the STL can be executed sequential, parallel, or vectorized.
  • The concurrency story in C++ goes on. With C++20/23 we can hope for executors, extended futures, coroutines, transactions, and more.

This book explains you the details to concurrency in modern C++ and gives you, in addition, more than 100 running code examples . Therefore you can combine the theory with the practices and get the most of it.

Because this book is about concurrency, I present a lot of pitfalls and show you how to overcome them.

About the Author

Rainer Grimm

I worked as a software architect, team lead and instructor for about 20 years. In my spare time, I like to write articles on the topics C++, Python and Haskell, but I also like to speak at conferences. Since 2016 I'm independent trainer giving seminars about modern C++ and Python.

My books "C++ 11 für Programmierer ", "C++" and "C++ Standardbibliothek kurz & gut" for the "kurz & gut" series were published by the publisher Pearson and O'Reilly. They are available in German, English, and Korean. In summer 2018 I published a new book at Leanpub: "Concurrency with Modern C++". This book is also available in German at Hanser: "Modernes C++: Concurrency meistern".

I'm the author of the two well-known blogs. in German in English

Bundles that include this book

Concurrency with Modern C++
The C++ Standard Library
Suggested Price
Bundle Price

Reader Testimonials

Bart Vandewoestyne
Bart Vandewoestyne

Senior Development Engineer Software at Esterline

'Concurrency with Modern C++' is your practical guide to getting familiar with concurrent programming in Modern C++. Starting with the C++ Memory Model and using many ready-to-run code examples, the book covers a good deal of what you need to improve your C++ multithreading skills. Next to the enlightening case studies that will bring you up to speed, the overview of upcoming concurrency features might even wet your appetite for more!

Ian Reeve
Ian Reeve

Senior Storage Software Engineer for Dell Inc.

Rainer Grimm's Concurrency with Modern C++ is a well written book covering the theory and practice for working with concurrency per the existing C++ standards, as well as addressing the potential changes for the upcoming C++ 20 standard. He provides a conversational discussion of the applications and best practices for concurrency along with example code to reinforce the details of each topic. An informative and worthwhile read!

Robert Badea
Robert Badea

Technical Team Leader

Concurrency with Modern C++ is the easiest way to become an expert in the multithreading environment. This book contains both simple and advanced topics, and it has everything a developer needs, in order to become an expert in this field: Lots of content, a big number of running code examples, along with great explanation, and a whole chapter for pitfalls. I enjoyed reading it, and I highly recommend it for everyone working with C++.

Table of Contents

    • Reader Testimonials
    • Introduction
      • Conventions
        • Special Fonts
        • Special Symbols
        • Special Boxes
      • Source Code
        • Run the Programs
      • How you should read the book?
      • Personal Notes
        • Acknowledgements
        • About Me
        • My Special Circumstances
  • A Quick Overview
    • Concurrency with Modern C++
      • C++11 and C++14: The Foundation
        • Memory Model
        • Multithreading
      • C++17: Parallel Algorithms of the Standard Template Library
        • Execution Policy
        • New Algorithms
      • Case Studies
        • Calculating the Sum of a Vector
        • Thread-Safe Initialisation of a Singleton
        • Ongoing Optimisation with CppMem
      • C++20/23: The Concurrent Future
        • Executors
        • std::jthread
        • Atomic Smart Pointers
        • Extended futures
        • Latches and Barriers
        • Coroutines
        • Transactional Memory
        • Task Blocks
      • Challenges
      • Best Practices
      • Time Library
      • CppMem
      • Glossary
  • The Details
    • Memory Model
      • Basics of the Memory Model
        • What is a memory location?
        • What happens if two threads access the same memory location?
      • The Contract
        • The Foundation
        • The Challenges
      • Atomics
        • Strong versus Weak Memory Model
        • The Atomic Flag
        • The Class Template std::atomic
        • All Atomic Operations
        • Free Atomic Functions
        • std::shared_ptr
      • The Synchronisation and Ordering Constraints
        • The Six Variants of Memory Orderings in C++
        • Sequential Consistency
        • Acquire-Release Semantic
        • std::memory_order_consume
        • Relaxed Semantic
      • Fences
        • std::atomic_thread_fence
        • std::atomic_signal_fence
    • Multithreading
      • Threads
        • Thread Creation
        • Thread Lifetime
        • Thread Arguments
        • Methods
      • Shared Data
        • Mutexes
        • Locks
        • Thread-safe Initialisation
      • Thread-Local Data
      • Condition Variables
        • The Predicate
        • Lost Wakeup and Spurious Wakeup
        • The Wait Workflow
      • Tasks
        • Tasks versus Threads
        • std::async
        • std::packaged_task
        • std::promise and std::future
        • std::shared_future
        • Exceptions
        • Notifications
    • Parallel Algorithms of the Standard Template Library
      • Execution Policies
      • Algorithms
      • The New Algorithms
        • More overloads
        • The functional Heritage
    • Case Studies
      • Calculating the Sum of a Vector
        • Single Threaded addition of a Vector
        • Multithreaded Summation with a Shared Variable
        • Thread-Local Summation
        • Summation of a Vector: The Conclusion
      • Thread-Safe Initialisation of a Singleton
        • Double-Checked Locking Pattern
        • Performance Measurement
        • Thread-Safe Meyers Singleton
        • std::lock_guard
        • std::call_once with std::once_flag
        • Atomics
        • Performance Numbers of the various Thread-Safe Singleton Implementations
      • Ongoing Optimisation with CppMem
        • CppMem: Non-Atomic Variables
        • CppMem: Locks
        • CppMem: Atomics with Sequential Consistency
        • CppMem: Atomics with Acquire-Release Semantic
        • CppMem: Atomics with Non-atomics
        • CppMem: Atomics with Relaxed Semantic
      • Conclusion
    • The Future: C++20/23
      • Executors
        • First Examples
        • Goals of an Executor Concept
        • Terminology
        • Execution Functions
      • A Cooperatively Interruptible Joining Thread
        • Automatically Joining
        • Interrupt a std::jthread
      • Atomic Smart Pointers
        • A thread-safe singly linked list
      • Extended Futures
        • Concurrency TS v1
        • Unified Futures
      • Latches and Barriers
        • std::latch
        • std::barrier
        • std::flex_barrier
      • Coroutines
        • A Generator Function
        • Details
      • Transactional Memory
        • ACI(D)
        • Synchronized and Atomic Blocks
        • transaction_safe versus transaction_unsafe Code
      • Task Blocks
        • Fork and Join
        • define_task_block versus define_task_block_restore_thread
        • The Interface
        • The Scheduler
  • Further Information
    • Challenges
      • ABA Problem
      • Blocking Issues
      • Breaking of Program Invariants
      • Data Races
      • Deadlocks
      • False Sharing
      • Lifetime Issues of Variables
      • Moving Threads
      • Race Conditions
    • Best Practices
      • General
        • Code Reviews
        • Minimise Sharing of mutable data
        • Minimise Waiting
        • Prefer Immutable Data
        • Use pure functions
        • Look for the Right Abstraction
        • Use Static Code Analysis Tools
        • Use Dynamic Enforcement Tools
      • Multithreading
        • Threads
        • Data Sharing
        • Condition Variables
        • Promises and Futures
      • Memory Model
        • Don’t use volatile for synchronisation
        • Don’t program Lock Free
        • If you program Lock-Free, use well-established patterns
        • Don’t build your abstraction, use guarantees of the language
        • Don’t reinvent the wheel
    • The Time Library
      • The Interplay of Time Point, Time Duration, and Clock
      • Time Point
        • From Time Point to Calendar Time
        • Cross the valid Time Range
      • Time Duration
        • Calculations
      • Clocks
        • Accuracy and Steadiness
        • Epoch
      • Sleep and Wait
    • CppMem - An Overview
      • The simplified Overview
        • 1. Model
        • 2. Program
        • 3. Display Relations
        • 4. Display Layout
        • 5. Model Predicates
        • The Examples
    • Glossary
      • ACID
      • CAS
      • Callable Unit
      • Concurrency
      • Critical Section
      • Executor
      • Function Objects
      • Lambda Functions
      • Lock-free
      • Lost Wakeup
      • Math Laws
      • Memory Location
      • Memory Model
      • Modification Order
      • Monad
      • Non-blocking
      • Parallelism
      • Predicate
      • RAII
      • Release Sequence
      • Sequential Consistency
      • Sequence Point
      • Spurious Wakeup
      • Thread
      • Total order
      • volatile
      • wait-free
    • Index

The Leanpub 45-day 100% Happiness Guarantee

Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Write and Publish on Leanpub

Authors, publishers and universities use Leanpub to publish amazing in-progress and completed books and courses, just like this one. You can use Leanpub to write, publish and sell your book or course as well! Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks. Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. It really is that easy.

Learn more about writing on Leanpub