C++中的std :: async和lambda函数没有关联状态

use*_*317 3 c++ lambda asynchronous exception c++11

我试图通过使用async在我的程序中获得更好的性能,只要这很方便.我的程序编译,但每次我使用包含异步调用的函数时,我都会收到以下错误:

C++ exception with description "No associated state"
Run Code Online (Sandbox Code Playgroud)

我试图用lambda调用异步的方式如下:

auto f = [this](const Cursor& c){ return this->getAbsIndex(c); };
auto nodeAbsIndex = std::async(f,node); // node is const Cursor&
auto otherAbsIndex = std::async(f,other); // other too

size_t from = std::min(nodeAbsIndex.get(), otherAbsIndex.get());
size_t to = std::max(nodeAbsIndex.get(), otherAbsIndex.get());
Run Code Online (Sandbox Code Playgroud)

呼叫功能的签名如下:

uint64_t getAbsIndex(const Cursor& c) const
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?谢谢你的任何提示!迭戈

mik*_*dld 9

你不能get()在同一个未来打两次电话.仔细阅读文档(相关部分valid()):http://en.cppreference.com/w/cpp/thread/future/get

在一个侧面说明,隐含铸造uint64_tsize_t也不好.后者的尺寸可能更小.