
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@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.