Why use async if all you do is wait for completion?

I came across some C ++ code, for example:

aThread->async( [=]() {
    // ... do stuff ...
} ).wait();

What is the point of running code in a thread if all you do is wait for completion? Why not replace the above code:

// ... do stuff ...
+3
source share
2 answers

Yes I agree. Creating a thread and then only waiting for the thread to finish is very small.

+2
source

It is possible that aThread has its own resources necessary to do the work, and you cannot use them or create them in the caller's thread.

0
source

All Articles