C++ Logo


Advanced search

Re: [wg14/wg21 liaison] (SC22WG14.19254) C memory object model study group - uninitialised reads and padding

From: Peter Sewell <Peter.Sewell_at_[hidden]>
Date: Thu, 15 Apr 2021 07:55:48 +0100
On Wed, 14 Apr 2021 at 16:54, JF Bastien <cxx_at_[hidden]> wrote:
>For atomics with padding, C++20 adopted the following change (and I expect
that compilers will implement it in previous versions as well):

I also don't understand P0528, I'm afraid - maybe I'm missing too much C++
context. It says:

"Because compare-and-exchange acts on an object’s value representation,
padding bits that never participate in the object’s value representation
are ignored. As a consequence, the following code is guaranteed to avoid
spurious failure: [ compare_exchange_strong of a struct with padding]"

In the case where the compare_exchange_strong is done with a hardware
compare-exchange instruction (which will examine padding), how would that
be implemented? By having the implementation first do another read of the
object's padding to combine with the expected value to form something that
can be compare-exchange'd ?

And where implemented with an LL/SC loop, by putting a padding-aware
comparison inside the loop?



Received on 2021-04-15 01:56:03