[cxx-abi-dev] thread_local CONstructors
Jakub Jelinek
jakub at redhat.com
Wed Sep 26 15:03:28 UTC 2012
On Wed, Sep 26, 2012 at 07:59:44AM -0700, Richard Henderson wrote:
> On 09/24/2012 08:49 PM, Jason Merrill wrote:
> > Jakub suggested that it would be more efficient for variables that do need dynamic initialization to have the wrapper check a guard variable before calling the init function rather than from within the init function. We could do that, too:
> >
> > extern void i_init() __attribute ((weak));
> > extern thread_local bool i_done __attribute ((weak));
> > inline int& i_wrapper()
> > {
> > if (i_init && !i_done) i_init();
> > return i;
> > }
> >
> > Note that we can't test the address of i_done to see if it's defined because undefined weak TLS variables resolve to a non-null pointer value. So we test the address of i_init instead.
>
> Given that I_DONE is thread_local, and could reside outside the current
> DSO, it is almost certain to require the use of the global-dynamic TLS
> model. Which itself implies a function call to __tls_get_addr.
For GD model sure, I was thinking about IE model, where it might be cheaper
than the call. But perhaps not significantly so.
As we'll need to do that on every access to the TLS variable (well, first
access in a function), it is going to be pretty expensive in any case.
Jakub
More information about the cxx-abi-dev
mailing list