I was reading the description of std::async at cppreference.com. The first description says :
The template function async runs the function f asynchronously (potentially in a separate thread which may be part of a thread pool) and returns a std::future that will eventually hold the result of that function call.
. [cppreference link]: std::async
What is the thread pool cppreference.com is talking about ?
I read the standard draft N4713 (C++ 17) and there is no mention of a possible thread pool usage. I also know that there is no thread pool in the standard C++ as of now.
cppreference and the C++ standard are in fact at odds about this. cppreference says this (emphasis and strikethrough mine):
The template function
async
runs the functionf
asynchronously (potentiallyoptionally in a separate thread which may be part of a thread pool).
Whereas the C++ standard says this:
If
launch::async
is set inpolicy
, [std::async
] calls [the function f] as if in a new thread of execution ...
And these are clearly two different things.
Only Windows' implementation of std::async
uses a thread pool AFAIK, while gcc and clang start a new thread for every invocation of std::async
(when launch::async
is set in policy
), and thus follow the standard.
More analysis here: https://stackoverflow.com/a/50898570/5743288
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With