title: Access thread-local from another thread
body: <p>How can I read/write a thread local variable from another thread?  That is, in Thread A I would like to access the variable in Thread B's thread local storage area. I know the ID of the other thread.</p>
  
  <p>The variable is declared as <code>__thread</code> in GCC. Target platform is Linux, but independence might be nice (GCC specific is okay however).</p>
  
  <p>Lacking a thread-start hook there is no way I can simply track this value at the start of each thread. All threads need to be tracked this way (not just specially started ones).</p>
  
  <p>A higher level wrapper like boost thread_local_storage or using pthread keys is not an option. I require the performance of using a true <code>__thread</code> local variable.</p>
  
  <hr>
  
  <p><em>FIRST ANSWER IS WRONG</em>: One cannot use global variables for what I want to do. Each thread must have its own copy of the variable. Furthermore, those variables must be <code>__thread</code> variables for performance reasons (an equally efficient solution would also be okay, but I know of none). I also don't control the thread entry points, thus there is no possibility for those threads to <em>register</em> any kind of structure.</p>
  
  <hr>
  
  <p><em>Thread Local is not private</em>: Another misunderstanding about thread-local variables. These are in no way some kind of <em>private</em> variable for the thread. They are globally addressable memory, with the restriction that their lifetime is tied to the thread. Any function, from any thread, if given a pointer to these variables can modify them. The question above is essentially about how to get that pointer address.</p>