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]: Fix blocking pthread_join.


On Wed, 2018-04-25 at 07:39 -0500, Carlos O'Donell wrote:
> On 04/25/2018 06:27 AM, Stefan Liebler wrote:
> > With this patch, the tid is loaded by dereferencing a volatile pointer.
> > Then the compiler is not allowed to reload the value for __tid from memory.

We always use atomic accesses when it comes to concurrently accessed
data (there are exceptions, but these are tightly controlled).
We never use volatile to "fix" concurrent accesses.

> > Okay to commit?
> 
> Would using an atomic type and an atomic load MO relaxed prevent the
> compiler from reloading from memory?

That's the right fix, and it should be an acquire MO load to synchronize
with the kernel's store to 0.  (We should make it a requirement for the
kernel to use a release store; IIRC, it is on many archs, but it isn't
documented.)

The accesses to the TID should be changed to use atomics everywhere, and
some (simple) concurrency notes should be added.

> I'm unhappy with the use of volatile here because it's not quite
> the real semantics. Sure, the memory is volatile, it may change at
> any point, but that's not what matters. What matters is that we load
> from that memory once and only once.

It's a normal concurrent access, so we're using atomics for it.
Volatile but non-atomic is for cases where one would communicate with an
external device or sth like that, and those device's memory accesses
would appear to interrupt the thread that's using the volatile accesses.
IOW, it's like sequential code from a memory-model perspective, just
that the device's accesses can interleave with the CPU thread's
accesses.  There's no such simple interleaving when it comes to
concurrent accesses.




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