Atomic Data Types
C++ has a set of simple atomic data types. These are booleans, characters, numbers and pointers in many variants. They need the header
<atomic>. You can define your atomic data type with the class template
std::atomic, but there are serious restrictions for your type
MyType there are the following restrictions:
- The copy assignment operator for
MyType, for all base classes of
MyTypeand all non-static members of
MyType, must be trivial. Only a compiler generated copy assignment operator is trivial.
MyTypemust not have virtual methods or base classes.
MyTypemust be bitwise copyable and comparable so that the C functions
memcmpcan be applied. Atomic data types have atomic operations. For example