[cpp-threads] Alternatives to SC

Hans Boehm Hans.Boehm at hp.com
Tue Jan 30 06:11:11 GMT 2007


On Mon, 29 Jan 2007, Doug Lea wrote:

> Boehm, Hans wrote:
> >>
> > I think that you should be able to write these using "raw" atomics in
> > C++.  The intent is for that to give you atomicity at low cost, which is
> > kind of what you get from normal Java variables.
>
> Sorry, I'm not sure I quite get this:
>
> If I want the kinds of variables that won't cause blow-ups
> after register spills etc, then I should use raw atomics. And the
> reason I should use them is that we aren't sure that optimizers
> would do the right thing of all "normal" variables were of this kind.
> Which wouldn't make one very confident that they'll do the right
> thing with raw atomics?
I think it's far easier to get them to do the right thing with raw
atomics.  The obvious way to implement those is with compiler intrinsics,
which look like (mostly) opaque function calls.  Since the compiler
doesn't know that "calling" these twice returns the same value, it can't
make erroneous deductions on that basis.

This admittedly precludes some optimizations.  But I think those are
typically orders of magnitude less important than optimizations on
ordinary variables.  And you could get them back as yu convinced
yourself they were safe.

Hans



More information about the cpp-threads mailing list