title: Thread Specific Data vs Thread Local Storage
body: <p>I've read Kerrisk's <a href="https://rads.stackoverflow.com/amzn/click/com/1593272200" rel="noreferrer" rel="nofollow noreferrer">The Linux Programming Interface: A Linux and UNIX System Programming Handbook</a>, Chapter 31 on Threads. The chapter include Thread Specific Data (Section 31.3.4) and Thread Local Storage (Section 31.4). The topics were covered on pages 663-669.</p>
  
  <p>Thread Specific Data (<code>pthread_key_create</code>, <code>pthread_setspecific</code>, <code>pthread_getspecific</code>, and friends) looks more powerful, but appears to be a little more cumbersome to use, and appears to use the memory manager more frequently.</p>
  
  <p>Thread Local Storage (<code>__thread</code> on static and global declarations) looks a little less powerful since its limited to compile time, but its appears to be easier to use, and appears to stay out of the memory manager at runtime.</p>
  
  <p>I could be wrong about the runtime memory manager since there could be code behind the scenes that calls <code>pthread_key_create</code> when it encounters <code>__thread</code> variables.</p>
  
  <p>Kerrisk did not offer a compare/contrast of the two strategies, and he did not make a recommendation on when to use which in a given situation.</p>
  
  <p>To add context to the question: I'm evaluating a 3rd party library. The library uses globals, does <em>not</em> utilize locking, and I want to use it in a multi-threaded program. The program uses threading to minimize network latencies.</p>
  
  <p>Is there a hands down winner? Or are there different scenarios that warrant using one or the other?</p>