[cxx-abi-dev] thread_local CONstructors

Jakub Jelinek jakub at redhat.com
Mon Sep 24 14:57:50 UTC 2012


On Mon, Sep 24, 2012 at 10:49:12AM -0400, Jason Merrill wrote:
> becomes (pseudo-code):
> 
> thread_local A_rep a1, a2;
> void tls_init()
> {
>   static bool done;

You mean
  static thread_local bool done;
right?  Though perhaps one could register just the TLS dtor
for the whole TU, and let it call the individual dtors in the right order
(and check the done TLS flag, if false and nothing has been initialized
in the current thread, just don't do anything).

> Unfortunately, since there is no way to tell whether a thread_local
> variable with external linkage has a dynamic initializer in another
> TU, we need to do the a1 to a1_f() transformation even for variables
> of POD type that are statically initialized.  I don't see a way to
> avoid this except doing POD initialization at thread creation time
> rather than lazily, which means significant changes outside the
> compiler.

That would be a big problem with dlopen when there is more than
one thread in the process at the time when dlopen is called and one of the
dlopened libraries has some thread_local vars that need constructing.

FOr destruction of thread_local vars, guess we can just make the
corresponding libraries non-dlclosable dynamically (as running destructors
in all threads upon dlclose would be a huge pain).

	Jakub


More information about the cxx-abi-dev mailing list