I am trying to understand how exactly thread_local qualifier works and where the actual variable gets stored? This is on C++.
Say I have a class with multiple member variables. An objet of the class is instantiated on heap and the object is shared between 2 threads. Appropriate locking mechanism is used to ensure two threads are not stomping on a member variable at same time.
There is a need for threads to keep track of few thread specific items. So I am thinking to create a thread_local variable in same header file as the Class declaration. As I understand, both threads will get their own copy of this variable, correct? Where exactly is the thread local variable stored in memory? If data segment, how exactly does the right variable gets picked up during execution?