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)

thread_ext.patch (6.6 KB ) - added by anonymous 12 years ago.
proposed patch to speedup access
5173_pthread.patch (4.0 KB ) - added by viboes 11 years ago.
patch tested in pthread platform

Download all attachments as: .zip

Change History (8)

by anonymous, 12 years ago

Attachment: thread_ext.patch added

proposed patch to speedup access

comment:1 by anonymous, 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 viboes, 11 years ago

Component: threadsthread

comment:3 by viboes, 11 years ago

Owner: changed from Anthony Williams to viboes
Status: newassigned

comment:4 by viboes, 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?

by viboes, 11 years ago

Attachment: 5173_pthread.patch added

patch tested in pthread platform

comment:5 by viboes, 11 years ago

Milestone: To Be DeterminedBoost 1.50.0

Committed in trunk r77838

comment:6 by viboes, 10 years ago

Resolution: fixed
Status: assignedclosed

Committed in release branch at [78543]

Note: See TracTickets for help on using tickets.