Is std::launch::async policy needed?

走远了吗. 提交于 2021-01-28 12:23:50

问题


What is the difference in the following:

std::async(my_function);

and

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

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


回答1:


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).

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.



来源:https://stackoverflow.com/questions/28659215/is-stdlaunchasync-policy-needed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!