首页 新闻 搜索 专区 学院

在线程中,写入了t1.detach();为什么输出还是和加入jion()时是一样的,感觉是没有起到线程的作用,编译器是VS2015

0
[待解决问题]

include<iostream>

include<thread>

include<string>

void Function_1()
{
std::cout << "study thread" << std::endl;
std::cout << "Function_1Thread 1" << std::endl;
std::cout << "Function_1Thread 2" << std::endl;
std::cout << "Function_1Thread 3" << std::endl;
std::cout << "Function_1Thread 4" << std::endl;
std::cout << "Function_1Thread 5" << std::endl;
std::cout << "Function_1Thread 6" << std::endl;
std::cout << "study thread end" << std::endl;
}

int main()
{
std::thread t1(Function_1);
std::cout << "T1Thread ID :" << t1.get_id() << std::endl;
t1.detach();
//t1.join();
std::cout << "MainThread ID :" << std::this_thread::get_id() << std::endl;
std::cout << "MainThread 1" << std::endl;
std::cout << "MainThread 2" << std::endl;
std::cout << "MainThread 3" << std::endl;
std::cout << "MainThread 4" << std::endl;
std::cout << "MainThread 5" << std::endl;
std::cout << "MainThread 6" << std::endl;
return 0;
}

逆光也很美的主页 逆光也很美 | 菜鸟二级 | 园豆:202
提问于:2019-05-11 10:22

不应该输出是混乱的吗?

逆光也很美 1年前
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册