April 2020
Intermediate to advanced
412 pages
9h 58m
English
We will create an application that spawns two worker threads to concurrently update an array of data. Instead of mutexes, we will use atomic variables to make sure the concurrent updates are safe.
#include <atomic>#include <chrono>#include <iostream>#include <thread>#include <vector>std::atomic<size_t> shared_index{0};std::vector<int> data;