Concurrency and Synchronization

In this chapter, we will learn how to properly handle concurrency, synchronization, and parallelism in C++. Here, it is essential that you have a general knowledge of C++ and C++ threads. This chapter is important because working with C++ typically requires the use of shared resources, which can easily become corrupt if thread-safety is not implemented properly. We will start with an extensive overview of std::mutexes, which provides a means to synchronizing C++ threads. We will then look at atomic data types, which provide another mechanism for handling parallelism safely.

This chapter has recipes that demonstrate how to handle different scenarios while working with C++ threads, including handling const &, thread-safety wrapping, blocking versus asynchronous programming, and C++ promises and futures. This is important, as this knowledge is critical when working with multiple threads of execution.

The following recipes are covered in this chapter:

  • Working with mutexes
  • Using atomic data types
  • Understanding what const & mutable mean in the context of multiple threads
  • Making a class thread-safe
  • Synchronization wrappers and how to implement them
  • Blocking operations versus asynchronous programming
  • Working with promises and futures
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset