[英]What happen to async member function after local object out of scope?
For example, if I can call an async function like this:例如,如果我可以像这样调用异步 function:
{
Example example;
example.asyncFuncInside();
}
Since the object is freed after the scope, will it have any risks on the ongoing task running inside the async function?由于 object 在 scope 之后被释放,它会对异步 function 内部运行的正在进行的任务有任何风险吗?
This cannot be answered in the current form.目前的形式无法回答这个问题。 If the "async" is a detached std::thread
, nothing bad happens.如果“异步”是分离的std::thread
,则不会发生任何不好的事情。 If the async function was implemented using std::async
, on the other hand, then asyncFuncInside
would return its std::future
, and since that's ignored the dtor of std::future
would block.另一方面,如果异步 function 是使用std::async
实现的,则asyncFuncInside
将返回其std::future
,并且由于忽略了std::future
的 dtor 将阻塞。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.