-
Book Overview & Buying
-
Table Of Contents
Concurrency with Modern C++
By :
std::atomic_ref (C++20)The class template std::atomic_ref applies atomic operations to the referenced non-atomic object. Concurrent writing and reading of atomic object is, therefore, no data race. The lifetime of the referenced object must exceed the lifetime of the atomic_ref. Accessing a subobject of the referenced object with an atomic_ref is not well-defined.
Accordingly to std::atomic, std::atomic_ref can be specialised and supports specialisations for the built-in data types.
std::atomic_ref
You can specialise std::atomic_ref for user-defined type, use partially specialisations for pointer types, or full specialisations for arithmetic types such as integral or floating-point types.
The primary template std::atomic_ref can be instantiated with a TriviallyCopyable type T.
struct Counters {
int a;
int b;
};
Counter counter;
std::atomic_ref<Counters> cnt(counter);
Change the font size
Change margin width
Change background colour