title: How to only disable destruction of objects in thread-local-storage?
body: <pre><code>#include &lt;cstdlib&gt;
  #include &lt;thread&gt;
  #include &lt;chrono&gt;
  
  using namespace std;
  using namespace std::literals;
  
  struct A
  {
      A() { cout &lt;&lt; "A()" &lt;&lt; endl; }    
      ~A() { cout &lt;&lt; "~A()" &lt;&lt; endl; }
  };
  
  A g_a;
  
  int main()
  {
      thread([]()
      {
          thread_local A a;
          this_thread::sleep_for(24h);
      }).detach();
  
      exit(0); // not ok
      quick_exit(0); // still not ok
  }
  </code></pre>
  
  <ul>
  <li>Global objects and objects in <code>thread-local-storage</code> will be
  destructed after calling <code>exit(0)</code>;</li>
  <li>Global objects and objects in <code>thread-local-storage</code> will not be
  destructed after calling <code>quick_exit(0)</code>;</li>
  </ul>
  
  <p>Is it possible:</p>
  
  <p><strong>Global objects are destructed after calling <code>some_exit_func(0)</code>; while objects in <code>thread-local-storage</code> are not destructed.</strong></p>
  
  <blockquote>
    <p><strong><em>Problem background:</em></strong></p>
    
    <p>I have a big legacy project, which has used <code>thread-local-storage</code> to
    store many C++ objects; before C++11, these objects will not be
    destructed automatically, so the former writer explicitly calls their
    destructors.</p>
    
    <p>Now, I want to recompile it with a C++11 compiler; I am faced with such a
    problem:</p>
    
    <ul>
    <li>If I use <code>exit(0)</code>, the objects in <code>thread-local-storage</code>  will be    double-destructed;</li>
    <li>If I use <code>quick_exit(0)</code>, the global variables will not be    destructed.</li>
    </ul>
  </blockquote>