[cxx-abi-dev] thread_local summary
Jason Merrill
jason at redhat.com
Tue Oct 2 02:11:07 UTC 2012
OK, I have an initial implementation working now, along the lines that I
discussed before.
For dynamic initialization of non-function-local thread_local variables,
I replace odr-uses of such variables with calls to an inline wrapper, i.e.
extern thread_local int i;
extern void i_init() __attribute__ ((weak));
inline i& i_wrapper() __attribute__ ((visibility ("internal")))
{
if (i_init) i_init();
return i;
}
The wrapper has internal visibility so that calls in PIC code resolve
locally. The compiler can avoid some of this when it can see the
definition of i.
I'm currently mangling the init and wrapper functions as normal
functions with a function name of _TH <object name> or _TW <object
name>, respectively. I've thought about dropping the function type from
the mangling, but don't have a strong opinion.
Registration of destructors is done via
__cxa_thread_atexit (void(*)(void *), void *);
which arranges to call the specified destructor for the specified object
when the thread exits. The destructors for the current thread are also
run on std::exit.
The standard specifies that these destructors should run before
destructors for objects with static storage duration, and my current
implementation doesn't get that right; I think it will be necessary to
change std::exit to guarantee this.
Dennis suggested that we still include the DSO handle in the parameters
to this function. Since there's really no way to run destructors in all
threads on dlclose, I don't really see the need; instead, an
implementation can use internal mechanisms to improve semantics and/or
diagnostics for dlclosing a shared object with pending thread_local
destructors.
Dennis also suggested renaming the function to __cxa_atexit_thread. I
don't have a strong preference.
Any opinions on the name, or the mangling of the init/wrapper functions?
Any other issues?
Jason
More information about the cxx-abi-dev
mailing list