0

As title, why std::async i called "async"? It makes me little confused, that name of template indicates parallel processing, but it can be (and sometimes is by default) synchronous?

Praetorian
  • 106,671
  • 19
  • 240
  • 328
  • possible duplicate of [Why using std::async from C++11?](http://stackoverflow.com/questions/17963172/why-using-stdasync-from-c11) – Steve Feb 02 '15 at 21:24
  • A true asynchronous call does not line up well with the rest of the language, nor it is terribly useful in general, at least in the context of "run this on another thread and I will deal with it later" from a purist stand point. At some point your main thread will need some kind of result from the async thread and if at that point the thread hasn't started executing then doing the work synchronously is better than performing a wait on the main thread. Attempting to describe "async when it makes sense" in an identifier is similarly complex. – Guvante Feb 02 '15 at 22:07
  • Well it makes more sense now. And way how it works is smart. Probably they could name it a little better, async keyword is (for me) strongly connected with parallelism. Thank you very much for your answer. – CursedHades Feb 02 '15 at 22:58

1 Answers1

-1

http://en.cppreference.com/w/cpp/thread/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. "

Evan Carslake
  • 2,267
  • 15
  • 38
  • 56
  • From same source: "In other words, f may be executed in another thread or it may be run synchronously when the resulting std::future is queried for a value." I know how it works, but name of this mechanism is for me little confusing. – CursedHades Feb 02 '15 at 21:39