是否需要std :: launch :: async策略? [英] Is std::launch::async policy needed?

查看:62
本文介绍了是否需要std :: launch :: async策略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下内容有何区别:

std::async(my_function);

std::async(std::launch::async, my_function);

在这种情况下,使用pilicy std :: launch :: async 有什么区别?无论如何,第一个选项是否不会异步启动该功能?

What is the difference in using the pilicy std::launch::async in this case?? Does the first option not launch the function asynchronously anyway??

推荐答案

第一个等效于传递 launch :: async |launch :: deferred ,在这种情况下,取决于异步启动还是仅推迟启动(具体取决于是否实现了)(当调用诸如 get()之类的非定时等待函数时调用)返回未来).

The first one is equivalent to passing launch::async | launch::deferred, in which case it is up to the implementation whether it is launched asynchronously or merely deferred (called when a non-timed waiting function like get() is called on the returned future).

这个想法是,默认情况下,如果创建新线程不会提高性能,则实现可以选择推迟.要强制创建新线程,请仅传递 launch :: async .

The idea is that by default, the implementation can choose to defer if creating a new thread isn't going to be a performance gain. To force a new thread to be created, pass launch::async only.

这篇关于是否需要std :: launch :: async策略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆