What Limitation of std::async is Stroustrup Referring To? What Limitation of std::async is Stroustrup Referring To? multithreading multithreading

What Limitation of std::async is Stroustrup Referring To?


The "problem" with std::async is that by default you don't know whether or not it starts a thread. If your function needs to run on a separate thread then this is a problem as your function might not run until get() or wait() is called.You can pass std::launch::async to ensure the function is launched on its own thread, which is like a std::thread that cannot BG e detached.


You pin pointed the problem.Threads can be recycled...So any use of thread_local storage is dangerous.

Your loop is just - but, as you mentioned, might be inefficient.

You can require the language to produce another thread using std::launch::async.But threads might still be recycled.