In below program i am getting error std::future_error: No associated state error.could anyone help why i am facing this error
#include <iostream>
#include <thread>
#include <future>
#include <chrono>
#include <functional>
void task(int& var, std::future<int>& refFuture)
{
std::packaged_task<int()> mytask{ [&](){var = 25; return var;}};
auto future = mytask.get_future();
mytask.make_ready_at_thread_exit();
refFuture = std::move(future);
}
int main()
{
int variable = 10;
std::future<int> future;
std::thread t1(task, std::ref(variable), std::ref(future));
std::future_status status = future.wait_for(std::chrono::seconds(0));
if(status == std::future_status::ready)
{
int myOutput = future.get();
std::cout << "Myoutput :" << myOutput << std::endl;
}
t1.join();
}