std::atomic<T>::is_lock_free (3) - Linux Manuals
std::atomic<T>::is_lock_free: std::atomic<T>::is_lock_free
Command to display std::atomic<T>::is_lock_free
manual in Linux: $ man 3 std::atomic<T>::is_lock_free
NAME
std::atomic<T>::is_lock_free - std::atomic<T>::is_lock_free
Synopsis
bool is_lock_free() const noexcept; (since C++11)
bool is_lock_free() const volatile noexcept;
Checks whether the atomic operations on all objects of this type are lock-free.
Parameters
(none)
Return value
true if the atomic operations on the objects of this type are lock-free, false otherwise.
Notes
All atomic types except for std::atomic_flag may be implemented using mutexes or other locking operations, rather than using the lock-free atomic CPU instructions. Atomic types are also allowed to be sometimes lock-free, e.g. if only aligned memory accesses are naturally atomic on a given architecture, misaligned objects of the same type have to use locks.
The C++ standard recommends (but does not require) that lock-free atomic operations are also address-free, that is, suitable for communication between processes using shared memory.
Example
// Run this code
#include <iostream>
#include <utility>
#include <atomic>
struct A { int a[100]; };
struct B { int x, y; };
int main()
{
std::cout << std::boolalpha
<< "std::atomic<A> is lock free? "
<< std::atomic<A>{}.is_lock_free() << '\n'
<< "std::atomic<B> is lock free? "
<< std::atomic<B>{}.is_lock_free() << '\n';
}
Possible output:
std::atomic<A> is lock free? false
std::atomic<B> is lock free? true
See also
atomic_is_lock_free checks if the atomic type's operations are lock-free
(function template)
(C++11)
specializes atomic operations for std::shared_ptr
atomic_is_lock_free(std::shared_ptr) (function template)
is_always_lock_free indicates that the type is always lock-free
(public static member constant)
[static] (C++17)
Pages related to std::atomic<T>::is_lock_free
- std::atomic<T>::is_always_lock_free (3) - std::atomic<T>::is_always_lock_free
- std::atomic<T>::atomic (3) - std::atomic<T>::atomic
- std::atomic<T>::compare_exchange_weak,std::atomic<T>::compare_exchange_strong (3) - std::atomic<T>::compare_exchange_weak,std::atomic<T>::compare_exchange_strong
- std::atomic<T>::exchange (3) - std::atomic<T>::exchange
- std::atomic<T>::fetch_add (3) - std::atomic<T>::fetch_add
- std::atomic<T>::fetch_and (3) - std::atomic<T>::fetch_and
- std::atomic<T>::fetch_or (3) - std::atomic<T>::fetch_or
- std::atomic<T>::fetch_sub (3) - std::atomic<T>::fetch_sub
- std::atomic<T>::fetch_xor (3) - std::atomic<T>::fetch_xor
- std::atomic<T>::load (3) - std::atomic<T>::load
- std::atomic<T>::operator++,++(int),--,--(int) (3) - std::atomic<T>::operator++,++(int),--,--(int)
- std::atomic<T>::operator+=,-=,&=,|=,^= (3) - std::atomic<T>::operator+=,-=,&=,|=,^=
- std::atomic<T>::operator= (3) - std::atomic<T>::operator=
- std::atomic<T>::operatorT (3) - std::atomic<T>::operatorT
- std::atomic<T>::store (3) - std::atomic<T>::store
- std::atomic(std::shared_ptr) (3) - std::atomic(std::shared_ptr)