Std :: async - std :: launch :: async | stand :: start :: delayed

I understand what std::async does with the following parameters.

  • std::launch::async
  • std::launch::deferred

However, what happens to std::launch::async | std::launch::deferred std::launch::async | std::launch::deferred ?

+6
source share
2 answers

Startup Policy std::launch::async | std::launch::deferred std::launch::async | std::launch::deferred means that the implementation can choose whether to apply the std::launch::async or std::launch::deferred policies. This choice may differ from call to call and cannot be resolved immediately.

An implementation that always selects one or the other is legal (this is what gcc does, always choosing a deferred one), like the one that selects std::launch::async before reaching a certain limit, and then switches to std::launch::deferred .

It also means that an implementation may delay the choice until the end. This means that an implementation can wait for a decision to be made until its hand is forcibly called by a call that has clearly different effects from deferred and asynchronous tasks, or until the number of tasks performed is less than the internal limit of the task. This is what just :: thread does.

Functions that call the solution: wait() , get() , wait_for() , wait_until() and the destructor of the last future object that refers to the result.

+9
source

Chaprer 30.6.8 ISO IEC 14882-2011 explains that launch::async | launch::deferred launch::async | launch::deferred means implementations should defer invocation or the selection of the policy when no more concurrency can be effectively exploited (the same as async without the policy parameter).

In practice, this means that the C ++ runtime should start new threads for each async , as long as there are unused CPU cores.

+3
source

Source: https://habr.com/ru/post/908881/


All Articles