c++ - How to only disable destruction of objects in thread-local-storage? -


#include <cstdlib> #include <thread> #include <chrono>  using namespace std; using namespace std::literals;  struct {     a() { cout << "a()" << endl; }         ~a() { cout << "~a()" << endl; } };  g_a;  int main() {     thread([]()     {         thread_local a;         this_thread::sleep_for(24h);     }).detach();      exit(0); // not ok     quick_exit(0); // still not ok } 
  • global objects , objects in thread-local-storage destructed after calling exit(0);
  • global objects , objects in thread-local-storage not destructed after calling quick_exit(0);

is possible:

global objects destructed after calling some_exit_func(0); while objects in thread-local-storage not destructed.

problem background:

i have big legacy project, has used thread-local-storage store many c++ objects; before c++11, these objects not destructed automatically, former writer explicitly calls destructors.

now, want recompile c++11 compiler; faced such problem:

  • if use exit(0), objects in thread-local-storage double-destructed;
  • if use quick_exit(0), global variables not destructed.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -