Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Which thread pool is cppreference.com talking about?

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.

like image 551
cyrildz Avatar asked Apr 26 '19 18:04

cyrildz


1 Answers

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 function f asynchronously (potentially optionally in a separate thread which may be part of a thread pool).

Whereas the C++ standard says this:

If launch::async is set in policy, [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

like image 172
Paul Sanders Avatar answered Sep 28 '22 10:09

Paul Sanders