c++ 线程detach 问题?



 #include <thread>
#include <iostream>
#include <boost/thread.hpp>

int main()
{
    for (int i = 0; i < 10; ++i)
    {
        std::thread([]()
        {
            std::cout << "hello" << std::endl;
        }).detach();
    }

    return 0;
}

运行结果:
图片描述

怎么会打印出5个hello来了....求解释....

c++11 thread C++

囧‖夏总‖ 9 years, 4 months ago

打印出5个的时候正好程序关闭了

···西风哥 answered 9 years, 4 months ago

Your Answer