This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Bug #20116: Clarify barrier-like and mutex-like behaviours of PD->lock.
- From: Torvald Riegel <triegel at redhat dot com>
- To: Florian Weimer <fweimer at redhat dot com>
- Cc: "Carlos O'Donell" <carlos at redhat dot com>, GNU C Library <libc-alpha at sourceware dot org>
- Date: Tue, 14 Mar 2017 13:26:10 +0100
- Subject: Re: [PATCH] Bug #20116: Clarify barrier-like and mutex-like behaviours of PD->lock.
- Authentication-results: sourceware.org; auth=none
- References: <3d358d5a-66eb-cf97-ad98-16061a838f1a@redhat.com> <be27bfc1-e860-4afa-3193-9f246a6dcc0d@redhat.com> <116d8b2d-dad1-c5f6-8cf7-59e0c969381d@redhat.com> <7299daa1-f56f-ecca-5e04-76279b9afde1@redhat.com> <31ac5901-dec8-da57-72bc-91854d2c656e@redhat.com>
On Tue, 2017-03-14 at 07:58 +0100, Florian Weimer wrote:
> On 03/14/2017 02:07 AM, Carlos O'Donell wrote:
> > On 02/14/2017 06:32 AM, Florian Weimer wrote:
> >> On 02/13/2017 07:49 PM, Florian Weimer wrote:
> >>> On 02/13/2017 02:29 PM, Carlos O'Donell wrote:
> >>>> + It is important to point out that PD->lock is being used as a POSIX
> >>>> + barrier and a POSIX mutex.
... is being used both similar to a one-shot semaphore and,
subsequently, as a mutex.
> The lock is taken in the parent to force
> >>>> + the child to wait, and then the child releases the lock, in effect a
> >>>> + barrier. However, this barrier-like effect is used only for
s/, in effect a barrier//
s/barrier-like effect is used/semaphore-like use is employed/
> >>>> + synchronizing the parent and child. After startup the lock is used
> >>>> + like a mutex to create a critical region during which a single owner
critical section
> >>>> + modifies the thread parameters.
> >>>
> >>> I had missed that the lock was reused for the scheduler parameter.
> >>>
> >>> But the current code still does not make sense to me. Why do we need to
> >>> keep a copy of the scheduler parameters at all? Is this just a cache to
> >>> improve performance, similar to what we used to do for the PID?
> >>
> >> The cache is used in the implementation of PTHREAD_PRIO_PROTECT mutexes. There are data races:
> >>
> >> https://sourceware.org/bugzilla/show_bug.cgi?id=21160
> >>
> >> I expect that the use of ->lock to protect these members will go away eventually.
> >
> > Yes, it's used in tpp.
> >
> > Given your current understand is the above additional text sufficient
> > to clarify the situation?
>
> Yes, I'm mostly fine with it. I wouldn't call it a “POSIX barrier” and
> “POSIX mutex” though, it clearly is not.
>
> Maybe use “as a barrier (acquired and released by different threads and
> as a mutex (acquired and released by the same thread, providing mutual
> exclusion)”.
It's not a barrier actually, but closer to a semaphore (the parent does
not wait for the child to arrive, but continues immediately after
posting...).