Re: [PATCH 11/18] seqcount: Introduce raw_write_seqcount_barrier()

Peter Zijlstra
2015-06-17T15:49:35Z

On Wed, Jun 17, 2015 at 07:57:12AM -0700, Paul E. McKenney wrote:
> On Wed, Jun 17, 2015 at 02:29:24PM +0200, Peter Zijlstra wrote:
> > I did leave off the READ/WRITE ONCE stuff, because I could not come up
> > with a scenario where it makes a difference -- I appreciate paranoia,
> > but I also think we should not overdo the thing.
>
> I can only conclude that you have not read this document:
>
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4455.html
>
> Specifically, please keep in mind that unless you mark either the variable
> or the memory access, the compiler is within its rights to assume that
> there are no concurrent accesses to that variable. For but one example,
> if you do a normal store to a given variable, then the compiler is
> within its rights to use that variable as temporary storage prior to
> that store. And yes, you can reasonably argue that no sane compiler
> would store something else to s->sequence given that it could free up
> a register by storing the incremented value, but the fact remains that
> you have given it permission to do so if it wants.

This is the "Optimizations without Atomics" section you're referring to.

It has words such as: "if the compiler can prove they are not accessed
in other threads concurrently" and "This requires escape analysis: the
compiler must see the full scope of the memory location 'p', or must
know that leaf functions don't capture 'p' and aren't used concurrently,
for this optimization to be valid."

But then it starts weasel wording and saying that the lack of
std::atomic<> usage implies a lack of concurrency, to which I strongly
object.

Esp. seeing how -ffreestanding does not have access to any of the atomic
stuff since its library bits and not language bits (something which I've
often said was a failure in the spec).