1

where is the storage of thread_local variables in memory ? Is it heap ?

I have implemented a per-thread basis bootstrap function for our application, something like:

thread_local bool bootstrapped_ = false; void Bootstrap() { if (bootstrapped_) return; thread_local ContextTable contexts; contexts_ = &contexts; thread_local IndexMapper indexer; indexer_ = &indexer; } ContextTable* Contexts() { if (!bootstrapped_) Bootstrap(); return contexts_; } extern IndexMapper* Indexer() { if (!bootstrapped_) Bootstrap(); return indexer_; } 

In the source code above, where is the memory for variables bootstrapped_ , contexts and indexer allocated ?

9
  • 3
    Why the obsession with "physical" location of variables in memory? Commented May 12, 2017 at 17:37
  • 1
    Heap and stack are implementation details. Commented May 12, 2017 at 17:37
  • @BoundaryImposition If these objects are allocated on StackFrame, then could there be possibility of StackFramSize not enough to hold the objects ? Commented May 12, 2017 at 17:38
  • 1
    The question asks where the thread local variables are stored. In the case of Windows, they are created outside of the normal heap and flat address space (for 64 bit mode accessed via segment register FS or GS (I don't remember which)). In some (or most?) cases, although the thread variables are effectively in a separate heap, they are mapped into each thread's address space. Commented May 12, 2017 at 18:20
  • 1
    @Monku: And, if you read the answers there, you'll find out. Commented May 12, 2017 at 19:26

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.