Boost logo

Boost :

Subject: Re: [boost] [thread] thread_specific_ptr performance
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2010-01-09 08:55:47


On 01/09/2010 02:57 PM, Stefan Strasser wrote:
> Am Saturday 09 January 2010 13:58:35 schrieb Andrey Semashev:
>>
>> The pointer to the thread-specific data is stored in TLS, last time I
>> checked. And there's no difference in terms of performance in how you
>> store the pointer - via __thread specifier or by manually calling
>> pthread APIs. In case of __thread the compiler will generate the
>> necessary calls to pthread for you, that all you win, AFAIU.
>
> how do you come to that conclusion?
>
> <<
> __thread int *ptr;
>
> int *get_current_thread_data(){
> return ptr;
> }
> >>
>
> <<
> _Z23get_current_thread_datav:
> .LFB2:
> pushl %ebp
> .LCFI0:
> movl %gs:ptr_at_NTPOFF, %eax
> movl %esp, %ebp
> .LCFI1:
> popl %ebp
> ret
> >>

Interesting. It seems that GCC is smarter than I thought. At least on x86.

However, __thread doesn't allow to register a cleanup function that is
required by Boost.Thread. You could create a dummy TLS with pthread API
for that, but then I'm not sure if you could reliably access __thread
variables from that function.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk