Hi,
I am facing std::__throw_future_error(int) () exception if i try to do std::future<bool>::get() ()
Note: this exception is thrown sometimes (2 out of 10 times)
here is my code snippet.
Code:
MyClass::MyClass()
{
futureNotification = prom.get_future();
}
void* thread_Fun(void *arg)
{
MyClass *ptr = (MyClass *)arg;
bool notification = ptr->GetFutureNotification();
if(notification)
{
// do relevant work.
}
}
bool MyClass::GetFutureNotification()
{
return futureNotification.get();
}
void MyClass::SetNotification()
{
prom.set_value(true);
}
class MyClass
{
std::promise<bool> prom;
std::future<bool> futureNotification;
public :
void SetNotification();
bool GetFutureNotification();
...
};
Can anyone let me know why the exception is thrown? Also why this exception is thrown sometimes and not always?
Note : i set the notification (SetNotification) from my other module of program.
My thread function (thread_Fun) will be waiting for notification from GetFutureNotification, when once the promise value is set the thread gets unblocked and proceed with its execution.
I appreciate your support in this regard.