C++ Logo

liaison

Advanced search

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

From: Uecker, Martin <Martin.Uecker_at_[hidden]>
Date: Thu, 15 Apr 2021 19:59:59 +0000
Am Donnerstag, den 15.04.2021, 20:20 +0200 schrieb Jens Maurer:
> On 15/04/2021 11.51, Uecker, Martin wrote:
> >
> > Am Donnerstag, den 15.04.2021, 08:44 +0100 schrieb Anthony Williams:
> > > Atomic atomic;
> > > Padded some_value=init();
> > >
> > > Thread 1:
> > > atomic=some_value;
> > >
> > > Thread 2:
> > > Padded local=some_value;
> > > Padded new_value=whatever();
> > >
> > > if(atomic->compare_exchange_strong(local,new_value))
> > > do_stuff();
> > C++ could also change to treating padding bytes similar
> > to C which would also solve the problems with
> > atomic_exchange_compare (including unions), align it
> > with C, and make low-level programming manipulating
> > padding bytes possible.
>
> From a C++ perspective, it seems undesirable to urge programmers
> to use "memcpy" in lieu of "Padded local=some_value" to get
> the desired behavior from the "if(cmpxchg)" operation.

For struct types a solution is to require padding to be
set to zero for all atomic stores.

Best,
Martin


Received on 2021-04-15 15:00:14