Title
structs with internal padding
Status
resolved
Section
[atomics]
Submitter
Herb Sutter

Created on 2008-10-17.00:00:00 last changed 171 months ago

Messages

Date: 2010-12-05.14:14:49

[ 2009-10 Santa Cruz: ]

NAD EditorialResolved. Addressed by N2992.

Date: 2010-12-05.14:14:49

[ Post Summit Anthony adds: ]

The resolution of LWG 923 should resolve this issue as well.

Date: 2010-10-21.18:28:33

[ Summit: ]

Move to open. Blocked until concepts for atomics are addressed.

Date: 2010-12-05.14:14:49

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:

  1. ill-formed, or
  2. well-defined.

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.)

History
Date User Action Args
2010-12-05 14:14:49adminsetstatus: nad editorial -> resolved
2010-10-21 18:28:33adminsetmessages: + msg4394
2010-10-21 18:28:33adminsetmessages: + msg4393
2010-10-21 18:28:33adminsetmessages: + msg4392
2008-10-17 00:00:00admincreate