lundi 1 avril 2019

Is it better to use the default launch policy for std::async with newer compilers?

It is well known that the default launch policy may lead to deferred execution when using std::async. See for example How does a C++ compiler choose between deferred and async execution for std::async?.

I had seen this behaviour here when using MinGW-W64 with gcc 5.2.0. Therefore I have got used to always passing std::launch::async as launch policy.

Yet lately I have realized that newer gcc versions behave different. When using MinGW-W64 and g++ 8.1.0, omitting the std::async launch policy also leads to asynchronous execution in the code of the example linked above. Therefore I do not see a clear advantage of the std::async launch policy anymore.

On the contrary, item 35 of Scott Meyer's "Effective Modern C++" seems to imply that the default lauch policy might prevent out-of-threads exceptions or lead to better load-balancing, if the C++ Standard Library implements a reasonable thread scheduler.

Is this the case? Should I therefore get used to sticking to the default launch policy? Is this the a general advice for all (relatively new) C++ compilers?

Aucun commentaire:

Enregistrer un commentaire