Book Image

Mastering C++ Multithreading

By : Maya Posch
Book Image

Mastering C++ Multithreading

By: Maya Posch

Overview of this book

Multithreaded applications execute multiple threads in a single processor environment, allowing developers achieve concurrency. This book will teach you the finer points of multithreading and concurrency concepts and how to apply them efficiently in C++. Divided into three modules, we start with a brief introduction to the fundamentals of multithreading and concurrency concepts. We then take an in-depth look at how these concepts work at the hardware-level as well as how both operating systems and frameworks use these low-level functions. In the next module, you will learn about the native multithreading and concurrency support available in C++ since the 2011 revision, synchronization and communication between threads, debugging concurrent C++ applications, and the best programming practices in C++. In the final module, you will learn about atomic operations before moving on to apply concurrency to distributed and GPGPU-based processing. The comprehensive coverage of essential multithreading concepts means you will be able to efficiently apply multithreading concepts while coding in C++.
Table of Contents (17 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
8
Atomic Operations - Working with the Hardware

STL organization


In the STL, we find the following header organization, and their provided functionality:

Header

Provides

<thread>

The std::thread class. Methods under std::this_thread namespace:

  • yield
  • get_id
  • sleep_for
  • sleep_until

<mutex>

Classes:

  • mutex
  • timed_mutex
  • recursive_mutex
  • recursive_timed_mutex
  • lock_guard
  • scoped_lock (C++17)
  • unique_lock

Functions:

  • try_lock
  • lock
  • call_once
  • std::swap (std::unique_lock)

<shared_mutex>

Classes:

  • shared_mutex (C++17)
  • shared_timed_mutex (C++14)
  • shared_lock (C++14)

Functions:

  • std::swap (std::shared_lock)

<future>

Classes:

  • promise
  • packaged_task
  • future
  • shared_future

Functions:

  • async
  • future_category
  • std::swap (std::promise)
  • std::swap (std::packaged_task)

<condition_variable>

Classes:

  • condition_variable
  • condition_variable_any

Function:

  • notify_all_at_thread_exit

In the preceding table, we can see the functionality provided by each header along with the features introduced with the 2014 and 2017 standards. In the following sections, we will take a detailed look at...