#include<iostream>
#include<thread>
using namespace std;
void function_1()
{
std::cout << "Hello,world!" << std::endl;
}
int main() {
std::thread t1(function_1); //t1 starts running.
//t1.join(); //main thread waits for t1 finish .等待子线程my_thread执行完之后,主线程才可以继续执行下,此时主线程会释放掉执行完后的子线程资源。
t1.detach();
system("pause");
return 0;
}
```但是执行结果还是会把“Hello,world! ”输出,这是程序哪里出了问题??
C++ thread的detach函数问题??
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
6条回答 默认 最新
threenewbee 2016-01-07 12:59关注system("pause");从字面上看好像是让当前程序暂停,但是实际上这个只是调用了一个pause的命令,并且不会让程序暂停。
解决 无用评论 打赏 举报