Opened 12 years ago
Closed 10 years ago
#5173 closed Feature Requests (fixed)
boost::this_thread::get_id is very slow
Reported by: | anonymous | Owned by: | viboes |
---|---|---|---|
Milestone: | Boost 1.50.0 | Component: | thread |
Version: | Boost 1.45.0 | Severity: | Optimization |
Keywords: | boost::this_thread::get_id(), main thread, thread_specific_ptr | Cc: |
Description
retrieval of the thread::id for the current thread should be as fast as accessing a pointer. This can be easily done, by using a static allocated boost::thread_specific_ptr implementation and buffer the boost::this_thread::get_id inside, initializing on first access (code placed into dll).
another thing is the retrieval of the main thread (currently not possible). Can this be done using the recurring static initialization pattern from the singleton in the pool library and putting that into linked code as well ?
something like boost::main_thread::get_id() ?
Attachments (2)
Change History (8)
by , 12 years ago
Attachment: | thread_ext.patch added |
---|
comment:1 by , 12 years ago
please find attached a proposed solution to the speedup the access to boost::this_thread::get_id, currently injected as inline code, but may of course reside in an object file shared to platform independent code. the solution for boost::main_thread does only work, if the dll is not load delayed at runtime, because then the assumption for the recurring static intialization in the singleton from boost::pool fails (before main) and threading and also the wron id becomes and issue. perhaps a more transparent solution, choosing the thread with the lowest (highets id ?) woudl serve better ?
comment:2 by , 11 years ago
Component: | threads → thread |
---|
comment:3 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 11 years ago
Hi,
I have refactored the code so that thread::id contains just a pthread_t or a windows handle. I guess this will give the performances you expect. I have no tested yet the code on windows.
To be able to use it you will need to define BOOST_THREAD_PROVIDES_BASIC_THREAD_ID.
See attached patch 5173_pthread.patch
Please, let me know what do you think?
comment:6 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Committed in release branch at [78543]
proposed patch to speedup access