liveBook · Manning

Bitwise comparison

As explained in C++ Concurrency in Action, Second Edition

A bitwise comparison determines equality by comparing the object representations of values rather than applying their value-level comparison operators.

For std::atomic<UDT>, compare-exchange compares object representations as if with memcmp, not by calling UDT’s comparison operators. section 5.2.6

This can make compare-exchange fail even when values compare equally:

  • A UDT’s comparison operators may use different semantics from comparing its representation. section 5.2.6
  • Padding bits may differ without affecting ordinary value comparisons. section 5.2.6

How C++ Concurrency in Action, Second Edition covers it

How deep it goes
Explains the memcmp-like comparison and its correctness risks, with rationale tied to user-supplied operations under internal locks.
What you can do after
Evaluate whether compare-exchange can fail despite value equality when comparison semantics or padding differ.
How it connects
Connects std::atomic user-defined types, compare-exchange, memcmp-like representation checks, and padding bits.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of C++ Concurrency in Action, Second Edition. The section links point to the parts of the book it draws on.