Reputation: 863
I'm trying to obtain a better performance in my program by using async whenever this is convenient. My program compiles, but I get the following error every time I use a function containing async calls:
C++ exception with description "No associated state"
The way I am trying to call async with a lambda is e.g. as follows:
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());
Signature of the function to call is as follows:
uint64_t getAbsIndex(const Cursor& c) const
What am I doing wrong here? Thanks for any hints! Diego
Upvotes: 3
Views: 6644
Reputation: 3049
You can't call get()
twice on the same future. Read documentation carefully (the part regarding valid()
): http://en.cppreference.com/w/cpp/thread/future/get
On a side note, implicitly casting uint64_t
to size_t
is not good. The latter could be of smaller size.
Upvotes: 12