Is it possible to assign a new value to the std :: future object without getting the result of the previous task?
For example:
std::future<TResult> f; // глобальная переменная TResult thread_func(params) { /* тут какие-то тяжелые вычисления */ } // запрос "долгой" операции (может поступить до окончания предыдущего расчета!) void RequestAsync() { f = std::async<TResult>(thread_func, some_params); } // проверяем получение результата (например, таймером) void CheckResult() { if (!f.valid()) return; TResult result = f.get(); } I tested this code and did not get any errors, but doubts about the correctness of such an assignment remain. For example, what will happen if several running threads return a parameter value at the same time? Will there be a memory leak when the thread tries to return a value through a variable already rewritten by async?