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?

Community
  • 1
  • 1
athos
  • 6,120
  • 5
  • 51
  • 95
  • "`async()` will utilize thread pool so cheaper" only on windows platform or everywhere - the thread pool? – Abhinav Gauniyal Sep 11 '16 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. – Some programmer dude Sep 11 '16 at 12:56
  • @JoachimPileborg any numbers? – athos Sep 11 '16 at 13:02
  • @AbhinavGauniyal my impression is on all , but depends on implementation of compiler and OS – athos Sep 11 '16 at 13:04
  • 2
    http://open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3780.pdf – Hans Passant Sep 11 '16 at 13:21
  • @HansPassant thx, so this is an update at 2013 Sept... – athos Sep 11 '16 at 13:23
  • 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. – Hans Passant Sep 11 '16 at 14:06
  • @HansPassant Sorry for my ignorant, who is Tony Williams? – athos Sep 11 '16 at 14:27
  • He's the pope of Unix and Boost threading and an influential committee member. Wrote "C++ Concurrency in Action". – Hans Passant Sep 11 '16 at 14:30

0 Answers0