[cpp-threads] High-level vs. low-level

Alexander Terekhov alexander.terekhov at gmail.com
Thu Jul 13 20:44:22 BST 2006


On 7/13/06, Peter Dimov <pdimov at mmltd.net> wrote:
> Herb Sutter wrote:
>
> > Leaving aside the difficulty of fences, a secondary issue with the
> > above is that from the point of view of language design this
> > multiplies the opportunities to go wrong -- specifically because it
> > requires the programmer to remember to say something special
> > (potentially) each time they read and write the variable, and each
> > time is an opportunity for the programmer to be human and forget,
> > with no safety net and silent compilation. At the very least, even
> > for the rocket scientists who'd want to do the above, wouldn't you
> > prefer to be able to declare x as a type that doesn't have regular
> > assignment available at all, and so _requires_ the programmer to
> > write code like the above (including e.g. atomic_store_normal when no
> > special fencing is required) so that you get a compile-time error
> > when you forget? Otherwise it's way too easy to forget, and I don't
> > believe the code is maintainable (experts might get the initial
> > coding right, but I don't believe it has a good chance to stay right
> > in the face of maintenance).
>
> This is a very good question. I'm still undecided on whether:
>
>     atomic_load_acq( &x );
>
> should work on x being a plain int.

Should not.

> It is possible to restrict the library
> to require the programmer to tag the x as allowing atomic operations. One
> problem with such a restriction is that it either requires changes to the
> type system:
>
>     int __atomic x;

Uh. And why not simply atomic_int (could use std::atomic<int> under
the cover a la <iohw.h> -> <hardware> from the TR, see Appendix C)?

regards,
alexander.



More information about the cpp-threads mailing list