0

我不确定为什么下面的代码在此处的在线编译器中运行时会引发运行时异常。我正在尝试通过打包任务执行功能

#include <iostream>
#include <future>

int display(int i)
{
    std::cout << "In display";
    return i + 1;
}

int main()
{
   std::packaged_task<int(int)> pt(display);
   auto fut = pt.get_future();
   pt(5);
   std::cout << "\n PT returns " << fut.get();
   return 0;
}

我得到的错误是

/tmp/RucY1KsPrS.o
terminate called after throwing an instance of 'std::system_error'
  what():  Unknown error -1
Aborted
4

0 回答 0