6

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?

9
  • "async() will utilize thread pool so cheaper" only on windows platform or everywhere - the thread pool? Commented Sep 11, 2016 at 12:53
  • Like most of everything else, it depends. What is the purpose of the thread? Is it supposed to be a long-living thread to e.g. handle network connections? Is it just doing some calculations and returning a result? For a long-running thread, the hit on performance for creating a thread is negligible, for a short-lived calculate-and-return-result thread, it might be considerate. Commented Sep 11, 2016 at 12:56
  • @JoachimPileborg any numbers? Commented Sep 11, 2016 at 13:02
  • 2
    open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3780.pdf Commented Sep 11, 2016 at 13:21
  • 2
    Yeah, that shiny toy did not last long. A bit dangerous to comment on this as an outsider. Afaik this feature pretty much requires a work-stealing threadpool to be effective. Microsoft did, Tony Williams didn't. They could not get a consensus on how to deal with thread-local storage and that killed it. Pretty remarkable that this wasn't thought through before they added it to the standard so there is probably more to it. Commented Sep 11, 2016 at 14:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.