Why does this usage of thread_local crash?

1k views Asked by At

I have reduced the problem to the following small code snippet:

struct tls {
    ~tls() {}
    void dont_opt_out() {}
};

thread_local tls tls_obj;

int main(int argc, char **argv) {
    tls_obj.dont_opt_out();
}

When executed the program crashes. Why?

I'm using gcc version 4.8.2 on Windows, I compile with g++ -std=c++11 main.cpp.

1

There are 1 answers

0
Maxim Egorushkin On

Try compiling your code as multi-threaded.

Under Cygwin, it is -mthreads option for both compiler and linker.