1

reading article on async and future:

void fun() {
    std::async(std::launch::async, []{ f(); }); // temporary's dtor waits for f()
    std::async(std::launch::async, []{ g(); }); // does not start until f() completes
}

got an impression that if fun is called it will block until g() is executed. Please tall me that I am wrong and there is some reasonable tasks pool behind std::async logic?

DuckQueen
  • 772
  • 10
  • 62
  • 134
  • No, you're correct. Futures returned from `std::async` with the `std::launch::async` policy will block on destruction. See [this question](http://stackoverflow.com/questions/23455104/why-is-the-destructor-of-a-future-returned-from-stdasync-blocking) for more details. – melak47 Jul 05 '15 at 15:55
  • However, that does not prevent launching several things in parallel - you simply have to keep the futures somewhere (which generally you'd want to do so you can retrieve the result later). Here's [an example](http://coliru.stacked-crooked.com/a/0f447fda2f610962) – melak47 Jul 05 '15 at 16:05

0 Answers0