我正在尝试通过函数使用 C++ 的标准库创建线程。
#include <iostream>
#include <thread>
using namespace std;
void print()
{
printf("PRINT\n");
printf("PRINT2\n");
}
void createThread()
{
thread newThread(print);
}
int main()
{
createThread();
cin.get();
}
Run Code Online (Sandbox Code Playgroud)
程序编译并运行,但一旦线程完成,它就会创建一个“调试错误”。有什么想法吗?