Modify

Ticket #5173 (closed Feature Requests: fixed)

Opened 3 years ago

Last modified 23 months ago

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

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

Change History

Changed 3 years ago by anonymous

proposed patch to speedup access

comment:1 Changed 3 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 3 years ago by viboes

  • Component changed from threads to thread

comment:3 Changed 2 years ago by viboes

  • Owner changed from anthonyw to viboes
  • Status changed from new to assigned

comment:4 Changed 2 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 2 years ago by viboes

patch tested in pthread platform

comment:5 Changed 2 years ago by viboes

  • Milestone changed from To Be Determined to Boost 1.50.0

Committed in trunk r77838

comment:6 Changed 23 months ago by viboes

  • Status changed from assigned to closed
  • Resolution set to fixed

Committed in release branch at [78543]

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


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

 
Note: See TracTickets for help on using tickets.