Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8685651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:37:55+00:00 2026-06-12T22:37:55+00:00

I need to access the thread ID from threads that I don’t control (it’s

  • 0

I need to access the thread ID from threads that I don’t control (it’s in an asynchronous callback function, and it get called from a set of different threads).

I’d like to know if accessing the thread ID is expensive in terms of performance ?

I’m planning to use either boost::this_thread::get_id() or GetCurrentThreadId() from windows.

To clarify, I need to have some local cache array ready for when the data arrives from my callback, and I’m planning, to avoid errors and locking to use a local cache for each thread, and access the right cache using the thread id.
Also because the data that comes is always of a different size, I can not put it in the stack, and I want to avoid creating and deleting heap data all the time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:37:56+00:00Added an answer on June 12, 2026 at 10:37 pm

    Windows stores all the thread specific information in the so called TEB. In x86 the fs register points to the start of this structure, in x64 it is the gs register.

    In x86 windows the thread id is stored at FS:[0x24], which presumably should be rather cheap to access. Storing the information in thread local storage involves one extra indirection (we get the address of the TLS from the TEB), so it’s basically the same as your handrolled private cache – just less work for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem is this: I have multiple competing threads (100+) that need to access
I need access to the uint64_t typedef from stdint.h in some wrapper code that
I know that's bad design, but I need access to the view from my
I have a method that is getting called from multiple threads. Each of the
I have two threads that access the same set of properties, but one only
I have two different modules that need access to a single file (One will
I need to access a components tag attribute like: <h:inputtext id=input_age/> from a backing
I need to access the commandline from within a C# application. I can't find
I need to access camera from a remote html page. I load this html
How do I access a global vector from an individual thread in MPI? I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.