Question
Is lock-free synchronization always superior to synchronization using locks?
In C++, there is one atomic type std::atomic<T>
. This atomic type may be lock-free or maybe not depending on the type T and on the current platform. If a lock-free implementation for a type is available in a platform for a type T, then most compilers would provide lock-free atomic<T>
. In this case, even if I want non-lock-free atomic<T>
I can't have it.
C++ standards decided to keep only one std::atomic<T>
instead of one std::atomic<T>
and one std::lock_free<T>
(partially implemented for specific types). Does this imply that, 'there is no case where using a non-lock-free atomic type would be a better choice over using a lock-free atomic type when the latter is available' ? (Mainly in terms of performance rather than ease-of-use).