Search code examples
c++stdasync

do I have to call get or wait on a std::async future


If I run it with launch::async then I know it will run anyway (I think thats what I read), but do I have to call get / wait in order to perform some sort of clean up.

I dont need the result, I just want a nice fire and forget.


Solution

  • Put attention, that destructor of returned future object will perform blocking wait until your task action will finish (and the corresponded shared state will become ready).

    See last paragraph on the page: https://en.cppreference.com/w/cpp/thread/future/~future