https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66967

            Bug ID: 66967
           Summary: thread local's destructor not called if compile with
                    -fno-use-cxa-atexit
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhykzhykzhyk at gmail dot com
  Target Milestone: ---

$ cat a.cc
#include <cstdio>
#include <thread>

struct A {
  A() { puts("CONS"); }
  ~A() { puts("DES"); }
};

static thread_local A a;

int main() {
  std::thread t1([]{ a; });
  t1.join();
  puts("X");
  std::thread t2([]{ a; });
  t2.join();
}
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/home/zhyk/gcc5-install/libexec/gcc/x86_64-unknown-linux-gnu/5.2.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --prefix=/home/zhyk/gcc5-install
--disable-multilib
Thread model: posix
gcc version 5.2.0 (GCC)
$ g++ -std=c++14 -fno-use-cxa-atexit a.cc -lpthread
$ ./a.out
CONS
X
CONS

Expected output:
CONS
DES
X
CONS
DES

Reply via email to