`is_lock_free()` reports whether operations on a particular atomic object are lock-free: `true` means they use atomic instructions directly, while `false` means the implementation uses an internal lock. This check matters when choosing atomics as a performance alternative to mutex-based synchronization. section 5.2.1 section 5.2.3
Checking an atomic boolean
Call `flag.is_lock_free()` on a `std::atomic<bool>` object to check whether its operations are lock-free. The type may use an internal mutex, so the result can guide whether an atomic-based implementation is likely to deliver the expected performance benefit. section 5.2.3
Use the result to inform implementation choices:
- If the check returns false, atomic operations may be emulated using an internal lock; a mutex-based implementation may be easier to get right and may avoid the hoped-for performance loss. section 5.2.1
- The check applies to a particular object. For a compile-time guarantee across supported hardware, C++17 provides `std::atomic<T>::is_always_lock_free`. section 5.2.1
