Short answer: they can't. This is necessary for portability of the language since C++ does not want to require that every platform to have lock-free support for a specific set of data sizes. Using std::atomic<T>
makes it easy for the library to transparently provide lock-free atomicity for some T
s and use a lock for others.
On the bright side, replacing T
with atomic<T>
in your codebase provides documentation of exactly what objects are used for synchronization, and provides protection against accidental non-atomic access to those objects.
Long answer: reinterpret_cast<std::atomic<decltype(t)>&>(t).store(value)
may actually work on some implementations during the right phase of the moon, but it's the purest evil.