所以我一直在尝试使用MinGW编译器在Windows上编译和运行以下代码.
#include <iostream>
#include <thread>
void test()
{
std::cout << "test" << std::endl;
}
int main()
{
std::thread t(test);
}
Run Code Online (Sandbox Code Playgroud)
我正在使用以下命令进行编译:
g++ -std=c++11 test.cpp -o test.exe
Run Code Online (Sandbox Code Playgroud)
现在问题是应该使用的MinGW版本,我已经尝试过我所知道的所有版本.
数字1不起作用,因为GCC 显然只在内部支持 pthread.
数字2确实编译,它基本上甚至输出test(参见输出的最后一行),但它也崩溃了错误:
terminate called without an active exception
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
test
Run Code Online (Sandbox Code Playgroud)
数字3和4再次进行编译,但它们不输出test而是立即崩溃,但具有更具描述性的输出:
terminate called after throwing …Run Code Online (Sandbox Code Playgroud)