Modify

Opened 7 years ago

Closed 5 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 7 years ago.
proposed patch to speedup access
5173_pthread.patch (4.0 KB) - added by viboes 5 years ago.
patch tested in pthread platform

Download all attachments as: .zip

Change History (8)

Changed 7 years ago by anonymous

Attachment: thread_ext.patch added

proposed patch to speedup access

comment:1 Changed 7 years ago by anonymous

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 Changed 6 years ago by viboes

Component: threadsthread

comment:3 Changed 6 years ago by viboes

Owner: changed from Anthony Williams to viboes
Status: newassigned

comment:4 Changed 5 years ago by viboes

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?

Changed 5 years ago by viboes

Attachment: 5173_pthread.patch added

patch tested in pthread platform

comment:5 Changed 5 years ago by viboes

Milestone: To Be DeterminedBoost 1.50.0

Committed in trunk r77838

comment:6 Changed 5 years ago by viboes

Resolution: fixed
Status: assignedclosed

Committed in release branch at [78543]

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain viboes.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.