1

我已将问题简化为以下小代码片段:

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

thread_local tls tls_obj;

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

执行时程序崩溃。为什么?

我在 Windows 上使用 gcc 版本 4.8.2,我使用g++ -std=c++11 main.cpp.

4

1 回答 1

1

尝试将您的代码编译为多线程。

在 Cygwin 下,它是-mthreads编译器和链接器的选项。

于 2013-11-29T09:45:17.720 回答