This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: Understanding why getaddrinfo_a and __gai_enqueue_request use recursive locks
- From: Carlos O'Donell <carlos at redhat dot com>
- To: Will Hawkins <whh8b at virginia dot edu>
- Cc: libc-help at sourceware dot org, Will Hawkins <hawkinsw at gmail dot com>
- Date: Mon, 25 Sep 2017 10:13:03 -0600
- Subject: Re: Understanding why getaddrinfo_a and __gai_enqueue_request use recursive locks
- Authentication-results: sourceware.org; auth=none
- References: <CAE+MWFvvbJT8g=mTAmyC8yi6gdnELgLpagdyFfHHm2rp4a9+ag@mail.gmail.com> <e11a201c-405f-e874-f091-881b5ce56a3d@redhat.com> <CAE+MWFuB4wU2v-mgae=sQwZFLhmtoivTEkRXXKheHQ1G_VRDnw@mail.gmail.com>
On 09/23/2017 08:44 AM, Will Hawkins wrote:
> This is what confused me -- thank you for the confirmation that I was
> not going crazy! After an hour of trying to figure out how the code
> did not deadlock every time, I finally looked at the
> initialization/definition of the mutex and saw that it was recursive.
We call this a belt-and-suspenders approach, particularly if there were
multiple callers in the past that might or might no have taken the lock.
In this case it looks like there is just one caller so the appropriate
patch would have to be:
* Remove locking from helper function.
* Add comments to helper function explaining that lock X must be held
before calling.
* Add comments in caller stating that lock must be taken before calling
helper function.
* Look to see if have a reasonable test that exercises this code path,
and if not add one (I think there are tests already that cover this
area of code).
That's just a rough sketch of the details. This fix doesn't need a
public bug since it's not a user visible feature, just an optimization.
--
Cheers,
Carlos.