This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Resolved status.
Section: 33.5 [atomics] Status: Resolved Submitter: Herb Sutter Opened: 2008-10-17 Last modified: 2016-01-28
Priority: Not Prioritized
View all other issues in [atomics].
View all issues with Resolved status.
Right now, the compare_exchange_weak loop should rapidly converge on the padding contents. But compare_exchange_strong will require a bit more compiler work to ignore padding for comparison purposes.
Note that this isn't a problem for structs with no padding, and we do already have one portable way to ensure that there is no padding that covers the key use cases: Have elements be the same type. I suspect that the greatest need is for a structure of two pointers, which has no padding problem. I suspect the second need is a structure of a pointer and some form of an integer. If that integer is intptr_t, there will be no padding.
Related but separable issue: For unused bitfields, or other unused fields for that matter, we should probably say it's the programmer's responsibility to set them to zero or otherwise ensure they'll be ignored by memcmp.
Proposed resolution: Using atomic<struct-with-padding>::compare_exchange_strong should be either:
I propose Option 1 for C++0x for expediency, though I'm not sure how to say it. I would be happy with Option 2, which I believe would mean that compare_exchange_strong would be implemented to avoid comparing padding bytes, or something equivalent such as always zeroing out padding when loading/storing/comparing. (Either implementation might require compiler support.)
[ Summit: ]
Move to open. Blocked until concepts for atomics are addressed.
[ Post Summit Anthony adds: ]
The resolution of LWG 923 should resolve this issue as well.
[ 2009-10 Santa Cruz: ]
NAD Editorial. Addressed by N2992.