I think I was wrong.
According to std::future::get documentation , valid() should return false after calling get .
Any shared state issued. valid() false after calling this method.
Digging a bit into the implementation of VC ++ get , there is an error:
virtual _Ty& _Get_value(bool _Get_only_once) { // return the stored result or throw stored exception unique_lock<mutex> _Lock(_Mtx); if (_Get_only_once && _Retrieved) _Throw_future_error( make_error_code(future_errc::future_already_retrieved)); if (_Exception) _Rethrow_future_exception(_Exception); _Retrieved = true; _Maybe_run_deferred_function(_Lock); while (!_Ready) _Cond.wait(_Lock); if (_Exception) _Rethrow_future_exception(_Exception); return (_Result); }
in principle, _Retreived should also be set to true if _Exception contains exception_ptr . by the time of throwing this variable is never set. it seems that when they tested it, they did not experience preparedness for the future, only for the future of unpreparedness, since the latter would not show this error.
source share