An atomic type makes its operations atomic in the C++ language sense and provides building blocks for synchronization between threads. These low-level facilities matter most when working close to the machine; mutexes and other higher-level tools can often avoid the need to manage memory-order details directly. section 5.0 section 5.2.1
Keep these practical limits in mind:
- Standard atomic types are declared in <atomic>. Check is_lock_free() to learn whether an operation uses atomic instructions or an internal lock; if it uses a lock, a mutex-based implementation may be easier to get right. section 5.2.1
- Atomic operations do not make unsynchronized accesses to other non-atomic data safe. A data race on non-atomic variables can cause undefined behavior. section 5.2
Table 5.1. The alternative names for the standard atomic types and their corresponding std::atomic<> specializations (view table figure)
| Corresponding specialization |
|
|---|---|
| atomic_bool | std::atomic<bool> |
| atomic_char | std::atomic<char> |
| atomic_schar | std::atomic<signed char> |
| atomic_uchar | std::atomic<unsigned char> |
| atomic_int | std::atomic<int> |
| atomic_uint | std::atomic<unsigned> |
| atomic_short | std::atomic<short> |
| atomic_ushort | std::atomic<unsigned short> |
| atomic_long | std::atomic<long> |
| atomic_ulong | std::atomic<unsigned long> |
| atomic_llong | std::atomic<long long> |
| atomic_ullong | std::atomic<unsigned long long> |
| atomic_char16_t | std::atomic<char16_t> |
| atomic_char32_t | std::atomic<char32_t> |
| atomic_wchar_t | std::atomic<wchar_t> |
Use the table to look up standard atomic type names and their corresponding std::atomic specializations. section 5.2.1
















