Workaround for blocking async?

前端 未结 2 2036
情歌与酒
情歌与酒 2020-12-14 02:11

The async call below is blocking because the destructor of the returned future is blocking:

void foo() {}

void foo_async() {
    std::async(std         


        
2条回答
  •  别那么骄傲
    2020-12-14 02:48

    If you really want to fire-and-forget the call to foo(), I would say your workaround is OK.

    Otherwise, just do auto f = std::async(std::launch::async, foo);, and possibly return the future from foo_async().

提交回复
热议问题