error: terminate called after throwing an instance of 'std::future_error' what(): std::future_error: No associated state
g++ --version 7.5.0 however, the same lines of code runs fine on QNX with same g++ version.
Also, if we spawn a new thread and move promise to that thread function as a parameter, then exception is not theown when set_value() is invoked on promise object.
My exact question being, if this is an expected behavior, Is there a way to transfer ownership of promise object so that some other thread can use it at a later point of time during execution. Other than spawning a new thread, but to be able to access promise from an already existing thread.
#include <future>
using namespace std;
int main()
{
promise<int> p1;
promise<int> p2(move(p1));
p1.set_value(99); // SIGSEGV!
}
p1
top2
and then set the state onp1
? What is that supposed to do?std::terminate
was called. A message describing the problem was displayed. What exactly is your question? Are you asking why it throws? Why terminate is called? How to achieve your intended task without throwing?throw/terminate
is the correct behaviour. You never created a future for the promise, so what exactlyset_value
is supposed to do?