The standard function std::async:
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.
There is two launch polices std::launch::async and std::launch::deferred. In my compiler's (GCC 6.2) standard library impelmentation, the first one always creates a new thread and the second one does lazy evaluation on the calling thread. By default std::launch::deferred
is used.
Is there some implementation which uses thread pool with size equal to the hardware threads available when std::launch::async
is specified to avoid creating two many threads when std::async
is used in recursive algorithm?
Microsoft's compiler and C++ runtime that it ships with Visual Studio does.
i am using this approach
dispatch
isasynk(..., async)
;post
isasynk(..., deferred)
;