有时我必须使用它std::thread来加速我的应用程序。我也知道join()等到线程完成。这很容易理解,但是调用detach()和不调用有什么区别?
我认为,如果没有detach(),线程的方法将单独使用线程工作。
不分离:
void Someclass::Somefunction() {
//...
std::thread t([ ] {
printf("thread called without detach");
});
//some code here
}
调用与分离:
void Someclass::Somefunction() {
//...
std::thread t([ ] {
printf("thread called with detach");
});
t.detach();
//some code here
}
翻过高山走不出你
炎炎设计
郎朗坤
什么时候该用Thread什么时候又该用Runnable呢
什么是递归,什么时候应该使用它?
什么时候使用request,什么时候使用response?
在实际应用中,什么时候使用请求重定向,什么时候使用请求转发呢?
相关分类