This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]