This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Implement allocate_once
On Fri, 2018-01-12 at 13:40 +0100, Florian Weimer wrote:
> Isn't a an acquire MO load potentially cheaper than an acquire fence?
> The fence needs to synchronize with all threads, while the load only
> needs to synchronize with threads which have performed release MO store
> (or stronger) on the variable?
It could be, potentially. But that, of course, depends on the hardware
(eg, on x86, the acquire fence is really just a compiler barrier), and
currently the load will remain as a separate load even though it could
just be merged with the CAS (though that may change once GCC starts to
optimize atomics).
The best option here would be to use a CAS that has acquire MO on the
failure path, but we don't have that in atomic.h currently. Even better
would be a strong version of that (which we don't have either,
currently). But all of that doesn't matter much for the slow path,
which is where you use the CAS.