std::atomic::is_lock_free(3)
π std::atomic::is_lock_free π
okay so bestie, this is the std::atomic::is_lock_free(3) page from the C++ Standard Libary manual, and weβre about to vibe-check whether your atomics are lock-free β¨
π NAME π
std::atomic::is_lock_free β std::atomic::is_lock_free
πΈ Synopsis πΈ
Two flavors, both noexcept, both here since C++11, iykyk:
bool is_lock_free() const noexcept; (1) (since C++11)
bool is_lock_free() const volatile noexcept; (2) (since C++11)
Checks whether the atomic operations on all objects of this type are lock-free.
π«Ά Parameters π«Ά
(none) β literally none, bestie. Not a single parameter. π
π 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 <atomic>
#include <iostream>
#include <utility>
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(C++11) β checks if the atomic type's operations are lock-free (function template).atomic_is_lock_free(std::shared_ptr)β specializes atomic operations forstd::shared_ptr(function template).is_always_lock_free[static](C++17) β indicates that the type is always lock-free (public static member constant).
okay thatβs the whole page, bestie π«Ά β source: http://cppreference.com, version/date: 2024.06.10, and the page is std::atomic::is_lock_free(3). periodt π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms