In this example, we will demonstrate how to perform a parallel computation task that will calculate prime numbers, using threading. In this example, the following inclusion files and namespaces are required:
#include <list>
#include <mutex>
#include <thread>
#include <iostream>
#include <algorithm>
#include <gsl/gsl>
using namespace gsl;
using namespace std::string_literals;
Calculating prime values is an expensive operation for large numbers, but thankfully, they can be calculated in parallel. It should be noted that in our example, we don't attempt to optimize our search algorithm, as our goal here is to provide a readable example of threading. There are many methods, some simple, for improving the performance of the code in this example.
To store the prime numbers that our program finds, we will...