我试图在方便的时候通过使用异步来获得更好的性能。我的程序可以编译,但每次使用包含异步调用的函数时都会出现以下错误:
C++ exception with description "No associated state"
我尝试使用 lambda 调用 async 的方式是例如如下:
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());
要调用的函数的签名如下:
uint64_t getAbsIndex(const Cursor& c) const
我在这里做错了什么?感谢您的任何提示!
迭戈
你不能打电话get()
两次在同一个未来。仔细阅读文档(有关的部分valid()
): http://en.cppreference.com/w/cpp/thread/future/get http://en.cppreference.com/w/cpp/thread/future/get
顺便说一句,隐式转换uint64_t
to size_t
不好。后者的尺寸可以更小。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)