Concurrency
Get a brief overview of what C++20 has to offer when it comes to concurrency.
We'll cover the following...
Atomics
The class template std::atomic_ref applies atomic operations to the referenced non-atomic object. Concurrent writing and reading of the referenced object can take place, therefore, with no data race. The lifetime of the referenced object must exceed the lifetime of the std::atomic_ref
. Accessing a sub-object of the referenced object with std::atomic_ref
is not thread-safe.
According to std::atomic, std::atomic_ref
can be specialized and supports specializations for the built-in data types.
struct Counter {
int a;
int b;
};
Counter counter;
std::atomic_ref<Counter> cnt(counter);
With C++20, we get two atomic smart pointers that are partial specializations of ...