# Modern C++ Concurrency in Practice: Get the most out of any machine (Rainer Grimm)

Memory Model: Atomics - Weak Memory Model This lesson gives a brief overview of the weak memory model regarding concurrency in C++. Case Study: Thread-Safe Initialization of a Singleton - Thread-Safe Singleton: std::call_once with std::once_flag This lesson explains the solution for the thread-safe initialization of a singleton problem using std::call_once with std::once_flag in C++. A Quick Overview - Multithreading in C++ Illustrating the fundamentals of multithreading in C++. Introduction - Guide to Follow this Course A shorthand guide to introduce different parts of this course and how to follow each chapter for a better understanding of the underlying concepts. A Quick Overview - Case Studies A short introduction to some pertinent case studies used in this course to apply the theory portions. Multithreading: Shared Data - Thread-Safe Initialization This lesson gives a brief introduction to thread safe initialization of variables in concurrent programming with C++. Multithreading: Threads - Managing Thread Lifetime This lesson gives an overview of how to use the join and detach functions to properly end thread execution in C++. Memory Model: Fences - Acquire and Release Fences This lesson gives an overview of acquire and release fences used in C++ as memory barriers. The Future: C++20 - Attaching Extended Futures This lesson discusses how one extended future can be attached to another in C++20. Multithreading: Shared Data - Issues of Mutexes: Avoiding Exceptions This lesson lists some caveats pertaining to mutexes and how to avoid them in C++. Memory Model: Fences - Fences as Memory Barriers This lesson introduces a concept of fences as memory barriers in C++. Multithreading: Shared Data - Types of Locks: std::unique_lock This lesson gives an overview of std::unique_lock which is a type of lock used in C++. Multithreading: Tasks - Introduction to std::async This lesson gives an introduction to std::async which is used in C++ for multithreading. Multithreading: Shared Data - Thread-Safe Initialization: Constant Expressions This lesson gives an overview of thread-safe initialization in the perspective of concurrency in C++ with Constant Expressions Memory Model: Synchronization and Ordering Constraints - Is the Acquire-Release Semantic Transitive? This lesson introduces the concept of the acquire-release semantic being transitive. Multithreading: Tasks - Introduction to Tasks This lesson gives an introduction to tasks which consist of promises and futures, and are an important part of multithreading in C++. Memory Model: Synchronization and Ordering Constraints - Acquire Release: The Typical Misunderstanding This lesson highlights a typical misunderstanding while using acquire-release in C++. Multithreading: Shared Data - Introduction to Mutexes This lesson gives an introduction to mutexes which are used in C++ for concurrency. Multithreading: Shared Data - Thread-Safe Initialization - Static Variables with Block Scope This lesson gives an overview of thread-safe initialisation with static variables in the perspective of concurrency in C++. Multithreading: Shared Data - Issues of Mutexes: Deadlocks This lesson gives an overview of deadlocks caused by improper mutex locking in C++. Multithreading: Threads - Arguments of Threads: Undefined behavior This lesson gives an example of undefined behavior caused by passing arguments improperly to threads in C++ Multithreading: Threads - Methods of Threads This lesson lists and explains the commonly used methods of threads in C++. Multithreading: Threads - Methods of Threads in Practice This lesson shows the application of commonly used thread methods such as get_id, hardware_concurrency, and joinable in C++. Memory Model: Atomics - Strong Memory Model This lesson gives a brief overview of the strong memory model regarding concurrency in C++. Multithreading: Threads - Creation of Threads This lesson gives an introduction on how to create threads in C++ using callable units such as functions and lambda functions. Multithreading: Condition Variables - Condition Variables This lesson explains condition variable such as wait s and their usage in C++ for multithreading purposes. Memory Model: The Contract - The Foundation & Challenges This lesson briefs the foundation and challenges in the C++ memory model. Memory Model: Atomics - Free Atomic Functions This lesson gives an overview of free atomic functions used from the perspective of concurrency in C++. Memory Model: Atomics - The Atomic Flag This lesson gives an overview of the atomic flag, which is used from the perspective of concurrency in C++. Multithreading: Shared Data - Thread-Safe Initialization: call_once and once_flag This lesson gives an overview of thread-safe initialization in the perspective of concurrency in C++. Multithreading: Threads - Introduction to Threads This lesson gives an introduction to threads in C++. Multithreading: Shared Data - Types of Locks: std::lock_guard This lesson gives an introduction to locks and explains std::lock_guard used in C++. Multithreading: Shared Data - Mutex Types and Locking Methods This lesson discusses different types of mutexes and their locking methods Multithreading: Tasks - Introduction to std::shared_future This lesson gives an introduction to std::shared_future which is used in C++ for multithreading. Case Study: Calculate Sum of a Vector - Multithreaded Summation: Using std::lock_guard This lesson explains the solution for calculating the sum of a vector problem using std::lock_guard in C++. Memory Model: Atomics - Atomic Operations on std::shared_ptr Have questions about Atomic Operations on std::shared_ptr? Go for it! Memory Model: Synchronization and Ordering Constraints - Introduction This lesson introduces the concepts of synchronization and ordering constraints in C++. Memory Model: Fences - Synchronization with Atomic Variables This lesson gives an overview of synchronization with atomic variables in C++. Multithreading: Threads - Arguments of Threads - Race Conditions and Locks This lesson defines race conditions, and explains how to address them in concurrent programming with C++ Multithreading: Tasks - async: Concurrent Calculation This lesson gives an overview of concurrent calculation used with std::async in C++ for multithreading. Memory Model: Fences - Synchronization with Fences This lesson gives an overview of synchronization with fences in C++. Multithreading: Threads - Passing Arguments to Threads This lesson gives an overview of how to pass arguments to threads in C++ – by copy and by reference. Multithreading: Shared Data - Introduction to Shared Data This lesson gives an introduction to how data can be shared between threads in C++. Memory Model: Atomics - All Atomic Operations This lesson lists all the useful atomic operations which are quite handy while working with concurrency in C++. Multithreading: Condition Variables - The Caveats of Condition Variables In this lesson, we discuss the lost wakeup and spurious wakeup pitfall of condition variables with concurrency in C++ Memory Model: Synchronization and Ordering Constraints - Relaxed Semantic This lesson gives an overview of relaxed semantic which is used in C++ for concurrency. Memory Model: Fences - The Three Fences This lesson gives an overview of the acquire, release, and full fences used in C++ as memory barriers. Multithreading: Tasks - Threads vs Tasks This lesson highlights the differences between threads and tasks used in C++ for multithreading. Multithreading: Tasks - Introduction to Promises and Futures This lesson gives an introduction to std::promise and std::future which are used in C++ for multithreading. Multithreading: Tasks - async: Fire and Forget This lesson gives an overview of fire and forget used with std::async in C++ for multithreading. Multithreading: Tasks - Promise and Future: Return a Notification This lesson teaches how to return a notification while using std::promise and future in C++ for multithreading. Case Study: Calculate Sum of a Vector - Single Threaded Summation: Ranged Based for Loops Explaining the solution for calculating the sum of a vector problem using ranged-based for loops in C++. Multithreading: Threads - Thread Lifetime Management: Warnings and Tips Some caveats and tips on the lifetime of threads in C++ coming your way… Multithreading: Shared Data - Types of Locks: std::shared_lock This lesson gives an overview of the std::shared_lock which is a type of lock used in C++. Multithreading: Local Data - Thread Local Data This lesson explains how data that is local to a thread is created Case Study: Calculate Sum of a Vector - Multithreaded Summation: Using fetch_add Method This lesson explains the solution for calculating the sum of a vector problem using the fetch_add method in C++. Case Study: Calculate Sum of a Vector - Multithreaded Summation: Using fetch_add Method with Relaxed Semantic This lesson explains the solution for calculating the sum of a vector problem using the fetch_add method with relaxed semantic in C++. Multithreading: Tasks - Introduction to std::packaged_task This lesson gives an introduction to std::packaged_task which is used in C++ for multithreading. Case Study: Thread-Safe Initialization of a Singleton - Introduction to Thread-Safe Meyers Singleton This lesson gives an introduction to a thread-safe version of Meyers singleton. Case Study: Thread-Safe Initialization of a Singleton - Double-Checked Locking Pattern This lesson gives an overview of the double-checked locking pattern for the problem of the thread-safe initialization of a singleton in C++. Case Study: Ongoing Optimization with CppMem - CppMem: Non-Atomic Variables This lesson gives an overview of non-atomic variables used in the context of CppMem. Case Study: Ongoing Optimization with CppMem - CppMem: Atomics with Sequential Consistency This lesson gives an overview of atomics with sequential consistency used in the context of CppMem. Case Study: Ongoing Optimization with CppMem - Conclusion This lesson gives a conclusion of CppMem and how it helps in optimization of programs. Parallel Algorithms of the Standard Template Library - The New Algorithms This lesson gives an overview of the new algorithms that are a part of C++17. Parallel Algorithms of the Standard Template Library - New Algorithms - A Functional Perspective This lesson gives an overview of the new algorithms that are a part of C++17. Multithreading: Tasks - Promise and Future : Return an Exception This lesson teaches how to return an exception while using std::promise and future in C++ for multithreading. Case Study: Calculate Sum of a Vector - Single Threaded Summation: Protection with Locks This lesson explains the solution for calculating the sum of a vector problem using locks in C++. Multithreading: Tasks - async: Start Policy This lesson gives an overview of start policy used with std::async in C++ for multithreading. Case Study: Calculate Sum of a Vector - Calculate Sum of a Vector: Conclusion This lesson concludes all the methods used to solve the problem of calculating the sum of a vector in C++. Case Study: Thread-Safe Initialization of a Singleton - Thread-Safe Singleton: Atomics This lesson explains the solution for the thread-safe initialization of singleton problem using atomics in C++. Case Study: Thread-Safe Initialization of a Singleton - Classical Meyers Singleton This lesson gives an overview of a classical Meyers Singleton in C++. Case Study: Thread-Safe Initialization of a Singleton - Conclusion This lesson concludes the performance measures of methods used in solving the thread-safe initialization of singleton problems in C++. The Future: C++20 - Introduction to Extended Futures This lesson gives an overview of extended futures, predicted to be introduced in C++20. The Future: C++20 - Creating New Futures This lesson discusses how one extended future can be attached to another in C++20. Case Study: Ongoing Optimization with CppMem - Introduction to CppMem This lesson gives an introduction to the case study of ongoing optimization with CppMem. Parallel Algorithms of the Standard Template Library - Execution Policies This lesson explains execution policies (introduced in C++ 17) in detail. Parallel Algorithms of the Standard Template Library - Parallel & Vectorized Execution This lesson explains parallel and vectorized execution policies, which were introduced in C++ 17, in detail. Parallel Algorithms of the Standard Template Library - Algorithms This lesson gives an overview of all 69 algorithms introduced in C++17. Case Study: Calculate Sum of a Vector - Multithreaded Summation: Using Atomic Variable This lesson explains the solution for calculating the sum of a vector problem using an atomic variable in C++. Case Study: Calculate Sum of a Vector - Single Threaded Summation: Protection with Atomics This lesson explains the solution for calculating the sum of a vector problem using atomics in C++. Case Study: Ongoing Optimization with CppMem - CppMem: Atomics with a Relaxed Semantic This lesson gives an overview of atomics with a relaxed semantic used in the context of CppMem. Case Study: Ongoing Optimization with CppMem - CppMem: An Overview This lesson gives a brief overview of CppMem and how it helps in optimization. The Time Library - Time Point This lesson gives a brief introduction to time point and its usage in C++ with the help of interactive examples. The Future: C++20 - The Two Flavors of Transactional Memory This lesson explains synchronized and atomic blocks in transactional memory. The Time Library - Clocks This lesson gives a brief introduction to clocks and their usage in C++ with the help of interactive examples. The Future: C++20 - Introduction to Coroutines This lesson gives an overview of coroutines, predicted to be introduced in C++20. Coding Examples - ABA This lesson explains the ABA problem: An analogy for a value being changed in between two successive reads for that value giving the same result. Best Practices - Multithreading: Shared Data This lesson gives an overall guide for best practices used to manage shared data in multithreaded applications in C++. Case Study: Calculate Sum of a Vector - Thread Local Summation: Using Local Variable This lesson explains the solution for calculating the sum of a vector problem using a local variable in C++. Case Study: Calculate Sum of a Vector - Thread Local Summation: Using Tasks This lesson explains the solution for calculating the sum of a vector problem using tasks in C++. Best Practices - General This lesson provides a simple set of rules for writing well-defined and fast, concurrent programs in modern C++. The Future: C++20 - Atomic Smart Pointers This lesson gives an overview of the atomic smart pointers, predicted to be introduced in C++20. Case Study: Ongoing Optimization with CppMem - CppMem: Atomics with Non-Atomics This lesson highlights atomics with non-atomics used in the context of CppMem. Best Practices - Memory Model This lesson provides a simple set of rules for efficiently using C++ memory models. Coding Examples - Moving Threads This lesson gives an overview of problems and challenges related to moving threads in C++. The Time Library - Time Duration This lesson gives a brief introduction to a time duration class template and explains it with the help of interactive examples. The Future: C++20 - Transactional Memory - An Overview This lesson gives an outline of transactional memory, predicted to be introduced in C++20. The Future: C++20 - Thread-Safe Linked List Using Atomic Pointers This lesson describes the use of thread-safe singly linked list using atomic pointers. Coding Examples - False Sharing This lesson gives an overview of a false sharing problem which might occur during the implementation of concurrency in C++. The Time Library - Sleep and Wait This lesson gives a brief introduction to sleep/wait and its usage in C++ with the help of interactive examples. Case Study: Ongoing Optimization with CppMem - CppMem: Locks This lesson gives an overview of locks used in the context of CppMem. Case Study: Thread-Safe Initialization of a Singleton - Thread-Safe Singleton: std::lock_guard This lesson explains the solution for thread-safe initialization of a singleton problem using std::lock_guard in C++. Case Study: Calculate Sum of a Vector - Thread Local Summation: Using Thread Local Data This lesson explains the solution for calculating the sum of a vector problem using thread local data in C++. Case Study: Ongoing Optimization with CppMem - CppMem: Atomics with an Acquire-Release Semantic This lesson gives an overview of atomics with acquire-release semantic used in the context of CppMem. Coding Examples - Deadlocks This lesson gives an overview of deadlocks which might occur during implementation of concurrency in C++. Glossary - Running Source Code on your own machine Teach yourself how to interact with and run source code examples of this course. Best Practices - Multithreading: Condition Variables This lesson elucidates best practices involving condition variables such as notify_one and notify_all in multithreaded applications in C++. Best Practices - Multithreading: Threads This lesson illustrates the best practices used to implement multithreaded applications in C++. The Future: C++20 - Coroutines: More Details This lesson clarifies more details regarding coroutines, including use-cases, design goals, and underlying concepts. Coding Examples - Breaking of Program Invariants This lesson explains challenges related to the breaking of program invariants during the implementation of concurrency in C++. The Time Library - From Time Point to Calendar Time This lesson gives a brief introduction to calendar time and its usage in C++ with the help of interactive examples. Coding Examples - Race Conditions This lesson gives an overview of race condition problems that might occur during the implementation of concurrency in C++. The Time Library - Time Duration Calculations This lesson will explain which time duration operations are supported in C++. The Future: C++20 - Task Blocks This lesson gives an overview of task-blocks, predicted to be introduced in C++20. Coding Examples - Blocking Issues This lesson explains the challenges of blocking issues while using a condition variable in C++. Coding Examples - Data Races This lesson gives an overview of data race problems which might occur during the implementation of concurrency in C++. Glossary - Glossary This lesson serves as a reference for the most important terms used in this course of concurrency with modern C++. About the Author - Personal Notes A short introduction about the mind behind this course. Memory Model: Atomics - std::atomic<bool> This lesson gives an overview of std::atomic which is used from the perspective of concurrency in C++. Memory Model: Synchronization and Ordering Constraints - Data dependencies with std::memory_order_consume This lesson explains data dependencies with std::mem_order_consume in C++. Case Study: Thread-Safe Initialization of a Singleton - Introduction This lesson gives an introduction to the problem of the thread-safe initialization of singletons, and how to solve it through various methods in C++. Memory Model: Synchronization and Ordering Constraints - Types of Synchronization & Ordering Constraints This lesson introduces the types of synchronization and ordering constraints in C++. A Quick Overview - C++20: The Concurrent Future A short introduction to concurrent future and all the new libraries and techniques which are predicted to be launched with C++20. Case Study: Calculate Sum of a Vector - Introduction An introduction to a problem of calculating the sum of a vector, and how to solve it through various methods in C++. A Quick Overview - C++17: Parallel Algorithms of the Standard Template Library A short introduction of parallel algorithms of the standard template library in C++17. Memory Model: Atomics - Spinlock vs. Mutex It’s very interesting to compare the active waiting of a spinlock with the passive waiting of a mutex. Let’s continue our discussing from the previous lesson and make a comparison between these two. The Future: C++20 - Latches and Barriers This lesson gives an overview of latches and barriers, predicted to be introduced in C++20. Case Study: Calculate Sum of a Vector - Thread Local Summation: Using an Atomic Variable with Relaxed Semantic This lesson explains the solution for calculating the sum of a vector problem using an atomic variable with relaxed semantic in C++. The Time Library - The Interplay of Time Point, Time Duration, and Clock This lesson highlights the interplay of time point, time duration, and clock. A Quick Overview - C++11 and C++14: The Foundation This lesson demonstrates the foundation and overview of concurrency in C++11 and C++14. Memory Model: Synchronization and Ordering Constraints - Acquire Release Semantic This lesson introduces the concept of the acquire-release semantic used in C++. A Quick Overview - Challenging Issues in C++ This lesson is a small guide to help you study the challenging issues that we face in concurrent programming. Memory Model: Synchronization and Ordering Constraints - std::mem_order_consume This lesson introduces std::mem_order_consume which is used for concurrency in C++. Memory Model: Synchronization and Ordering Constraints - Sequential Consistency Familiarize yourself with sequential consistency in C++. Case Study: Calculate Sum of a Vector - Thread Local Summation: Using an Atomic Variable with Sequential Consistency This lesson explains the solution for calculating the sum of a vector problem using an atomic variable with sequential consistency in C++. Memory Model: The Contract - The Contract This lesson briefs the start of the C++ memory model with an introduction to the contract between the programmer and the system. Case Study: Thread-Safe Initialization of a Singleton - Performance Measurement This lesson gives an overview of the performance measurement for the problem of thread-safe initialization of a singleton in C++. Memory Model: Atomics - User Defined Atomics This lesson gives an overview of user-defined atomics used from the perspective of concurrency in C++. Case Study: Calculate Sum of a Vector - Single Threaded Summation: Addition with std::accumulate This lesson explains the solution for calculating the sum of a vector problem using std::accumulate in C++. Coding Examples - Lifetime Issues of Variables This lesson explains challenges related to lifetime issues of variables in C++.