GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::atomic_ref::compare_exchange_weak,std::atomic_ref::compare_exchange_strong(3) C++ Standard Libary std::atomic_ref::compare_exchange_weak,std::atomic_ref::compare_exchange_strong(3)

std::atomic_ref::compare_exchange_weak,std::atomic_ref::compare_exchange_strong - std::atomic_ref::compare_exchange_weak,std::atomic_ref::compare_exchange_strong


bool compare_exchange_weak( T& expected, T desired,


std::memory_order success, (1) (since C++20)


std::memory_order failure ) const noexcept;
bool compare_exchange_weak( T& expected, T desired,


std::memory_order order = (2) (since C++20)


std::memory_order_seq_cst ) const noexcept;
bool compare_exchange_strong( T& expected, T desired,


std::memory_order success, (3) (since C++20)


std::memory_order failure ) const noexcept;
bool compare_exchange_strong( T& expected, T desired,


std::memory_order order = (4) (since C++20)


std::memory_order_seq_cst ) const noexcept;


Atomically compares the value representation of the referenced object with that of
expected, and if those are bitwise-equal, replaces the former with desired (performs
a read-modify-write operation). Otherwise, loads the actual value stored in the
referenced object into expected (performs a load operation).


The memory models for the read-modify-write and load operations are success and
failure respectively. In the (2) and (4) versions order is used for both
read-modify-write and load operations, except that std::memory_order_acquire and
std::memory_order_relaxed are used for the load operation if order ==
std::memory_order_acq_rel, or order == std::memory_order_release respectively.


expected - reference to the value expected to be found in the object referenced by
the atomic_ref object
desired - the value to store in the referenced object if it is as expected
success - the memory synchronization ordering for the read-modify-write operation
if the comparison succeeds. All values are permitted.
the memory synchronization ordering for the load operation if the
failure - comparison fails. Cannot be std::memory_order_release or
std::memory_order_acq_rel
order - the memory synchronization ordering for both operations


true if the referenced object was successfully changed, false otherwise.


The comparison and copying are bitwise (similar to std::memcmp and std::memcpy); no
constructor, assignment operator, or comparison operator are used.


The weak forms (1-2) of the functions are allowed to fail spuriously, that is, act
as if *this != expected even if they are equal. When a compare-and-exchange is in a
loop, the weak version will yield better performance on some platforms.


When a weak compare-and-exchange would require a loop and a strong one would not,
the strong one is preferable unless the object representation of T may include trap
bits, or offers multiple object representations for the same value (e.g.
floating-point NaN). In those cases, weak compare-and-exchange typically works
because it quickly converges on some stable object representation.


For a union with bits that participate in the value representations of some members
but not the others, compare-and-exchange might always fail because such padding bits
have indeterminate values when they do not participate in the value representation
of the active member.


Padding bits that never participate in an object's value representation are ignored.


This section is incomplete
Reason: no example

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.