Async() vs threading on performance and control

2019-03-30 03:28发布

I am watching GoingNative 2012 Day 1 talk "C++11 style" by Bjarne Stroustrup , since 1:05:13 he seems was promoting async() than threading.

I do wonder, now 4 years passed, in C++ world, what's the pros and cons of async() vs threading, in terms of performance and control?

There're different opinions that I got lost:

For example, on performance: one SO post C++11 thread vs async performance (VS2013) says creating a thread is expensive ("200 000 CPU cycles in Windows OS") but async() will utilize thread pool so cheaper; but another SO post Will async(launch::async) in C++11 make thread pools obsolete for avoiding expensive thread creation? don't think so ("OSes have a lot of reasons they should be making thread creation as cheap as possible")

On control, previously my impression is threading allows more control; but an SO post async vs threading, when to use each option? on C# says "Threads have SOME Advantages when yo uneed control over the low Level thread Parameters - which is VERY rare. "

Also, I suppose the performance / control depends deeply on the implementation. So I wonder, 4 years after Bjarne promoting async(), how is it doing in C++ world, comparing with threading, in terms of performance and control?

0条回答
登录 后发表回答