This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Thread-local support for non-POD data objects
- From: Rich Felker <dalias at aerifal dot cx>
- To: Siddhesh Poyarekar <siddhesh at redhat dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Fri, 12 Jul 2013 16:10:36 -0400
- Subject: Re: Thread-local support for non-POD data objects
- References: <20130712172128 dot GC32671 at spoyarek dot pnq dot redhat dot com>
On Fri, Jul 12, 2013 at 10:51:28PM +0530, Siddhesh Poyarekar wrote:
> hi,
>
> There's an item on the glibc TODO master that mentions glibc support
> for non-POD objects. I believe the glibc support required here is
> limited to providing support for registering destructors and executing
> them on thread exit. This is true for C++11 thread_local as well as
> openmp thread local objects. This feature has been provided in glibc
> for 2.18, so I believe we could remove this item from the list. Does
> anybody have any objections to that?
>
> There's still the question of providing a C extension that implements
> a similar requirement, but that only needs compiler support now
> afaict.
Why is this needed in libc at all? My understanding is that the
thread-local ctors run when the C++ thread-creation function is used,
because pthread_create is called with a C++-implementation-internal
start function wrapping the application-provided start function. If
this is correct, then the start function provided by C++ could simply
use pthread_cleanup_push to install a cleanup handler that runs the
dtors, and run them manually with pthread_cleanup_pop(1) if the
application's start function returns. This would cover both
cancellation and pthread_exit or equivalent.
Am I missing some obvious reason this would not work?
Rich