I am trying to understand how the thread_local qualifier works and where is the actual variable stored? This is in C ++.
Say I have a class with several member variables. A class object is created on the heap, and the object is split between two threads. An appropriate locking mechanism is used to ensure that two threads do not stomp on a member variable at the same time.
There is a need for threads to track multiple items related to a stream. Therefore, I am going to create a thread_local variable in the same header file as the class declaration. As far as I understand, both threads will get their own copy of this variable, right? Where exactly is the local stream variable stored in memory? If a data segment, how exactly is the correct variable selected at runtime?
source share