How to do it...

In this section, we are going to implement some functions that simulate computation-intensive tasks that depend on each other, and let them run as parallel as possible:

  1. Let's first include all the necessary headers:
      #include <iostream>      #include <iomanip>      #include <thread>      #include <string>      #include <sstream>      #include <future>            using namespace std;      using namespace chrono_literals;
  1. We need to synchronize concurrent access to cout, so let's use the synchronization helper from the other recipe in this chapter:
      struct pcout : public stringstream {          static inline mutex cout_mutex;                ~pcout() {              lock_guard<mutex> l {cout_mutex};              cout << rdbuf();              cout.flush();          }      };
  1. Now let's implement three functions which transform strings. ...

Get C++17 STL Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.