如何在不暂停主函数的情况下并行启动一个新线程?
这是我的代码:
void someFunction { while(1);}
int main(){
thead *th = new thead(&someFunction);
thead.join();
return 0;
}
但是程序并没有停止
附言如何在并行源中运行线程
最佳答案
在 C++11 中,实现是 permitted to assume that this kind of loop terminates .所以你的代码可以优化到什么都没有。否则,许多合法且有值(value)的优化将无法实现,但有时效果会令人惊讶。
关于c++ - 多任务处理在我的 C++11 程序中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8915212/