This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] nptl: Add pthread_thread_number_np function
- From: Rich Felker <dalias at libc dot org>
- To: Florian Weimer <fweimer at redhat dot com>
- Cc: Carlos O'Donell <carlos at redhat dot com>, libc-alpha at sourceware dot org
- Date: Fri, 2 Mar 2018 13:04:16 -0500
- Subject: Re: [PATCH] nptl: Add pthread_thread_number_np function
- Authentication-results: sourceware.org; auth=none
- References: <20171214185611.D08E1439942EA@oldenburg.str.redhat.com> <fb88e4c8-2876-d085-25f9-bb3c2695ddd7@redhat.com> <82837141-5baa-bb34-607b-fe8de3199c9c@redhat.com>
On Fri, Dec 15, 2017 at 08:47:54AM +0100, Florian Weimer wrote:
> >We could allocate the thread numbers lazily, and that would certainly
> >avoid limiting ourselves to only allocating 2^64-1 threads. On top of
> >that if the function could return an error then we could return such
> >an error at overflow:
> >
> > int pthread_thread_number_np (uint64_t* thread_number, pthread_t @var{thread})
> >
> >Returns 0 if the thread has a unique number, otherwise -1 if it does not.
>
> That's a bad interface. If you are worried about 64-bit overflow,
> we should use a 128-bit counter instead, but I'm not convinced this
> is necessary.
>
> Lazy allocation would make the function not safe for use in signal handlers.
This is trivially false. You just have to block and restore signal
mask around taking and releasing the lock to make it AS-safe.
I'm also rather unhappy with an API whose external interface is an
assumption that you can never create more than 2^64 threads, even
though from a practical standpoint is seems impossible for the
forseeable future. Just documenting a special return value
(UINT64_MAX? 0?) that means the result was not meaningful would be a
decent fix, given that this whole interface is of dubious utility..
Rich