|
Boost : |
Subject: Re: [boost] [thread] thread_specific_ptr performance
From: Stefan Strasser (strasser_at_[hidden])
Date: 2010-01-11 09:22:31
Am Saturday 09 January 2010 12:57:33 schrieben Sie:
>
> <<
> __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
I've tried the same thing on MSVC with declspec(thread) and the result is
similar.
even though I understand the need for it now, it still seems odd
that we use a std::map to simply access a value in another memory segment.
have you thought about dynamically allocating an index into a
(thread-specific) vector instead of a key based on the thread_specific_ptr's
address?
IIUC that would allow constant-time access in all cases.
there are some similarities to Boost.Interprocess shared memory segments, the
dynamically allocated index would sort-of be an offset_ptr into a "thread
specific segment".
with the difference that the objects themselves can be stored outside of the
segment (which makes "growing the segment" a lot easier) and that
a "thread-specific segment" must be duplicated when a new thread is started
(or on first access).
but this seems solvable and if the allocator is able to not only store
destruction but also construction information, thread specific instances
could be supported in addition to thread specific pointers.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk