orlp
orlp

Reputation: 117641

Why does this usage of thread_local crash?

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.

Upvotes: 1

Views: 1107

Answers (1)

Maxim Egorushkin
Maxim Egorushkin

Reputation: 136208

Try compiling your code as multi-threaded.

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

Upvotes: 1

Related Questions