title: Setting all TLS (thread local storage) variables to a new, single value in C++
body: <p>I have a class Foo with the following thread-specific static member:</p>
  
  <pre><code>__declspec(thread) static bool s_IsAllAboutThatBass;
  </code></pre>
  
  <p>In the implementation file it is initialized like so:</p>
  
  <pre><code>__declspec(thread) bool Foo::s_IsAllAboutThatBass = true;
  </code></pre>
  
  <p>So far so good. Now, any thread can flip this <code>bool</code> willy nilly as they deem fit. Then the problem: at some point I want each thread to reset that <code>bool</code> to its initial <code>true</code> value.</p>
  
  <p><strong>How can I slam all instances of the TLS to true from a central thread?</strong></p>
  
  <p>I've thought of ways I could do this with synchronization primitives I know about, like critical sections, read/write sections, or events, but nothing fits the bill. In my real use cases <strong>I am unable to block any of the other threads for any significant length of time.</strong> </p>
  
  <p>Any help is appreciated. Thank  you!</p>
  
  <p><strong>Edit: Plan A</strong></p>
  
  <p>One idea is to use a <em>generation token</em>, or <em>cookie</em> that is read by all threads and written to by the central thread. Each thread can then have a TLS for the last generation viewed by that thread when grabbing <code>s_isAllAboutThatBass</code> via some accessor. When the thread local cookie differs from the shared cookie, we increment the thread local one and update <code>s_isAllAboutThatBass</code> to <code>true</code>. </p>