История изменений
Исправление ox55ff, (текущая версия) :
Я спросил как проверить не блокируя основной поток, вы привели пример как блокировать «на какой-то совсем короткий интервал времени»
Если у фьючи уже есть результат, то блокировки не будет. Если время ожидания равно нулю, то блокировки не будет. Ты не разобрался как работают фьючи, но обвиняешь людей, которые пытаются тебе помочь. Какого эффекта, ты хочешь добиться? Чтобы в твоей теме остались одни тролли, а понимающие люди забили на тебя?
future_status
wait_for(const chrono::duration<_Rep, _Period>& __rel)
{
// First, check if the future has been made ready. Use acquire MO
// to synchronize with the thread that made it ready.
if (_M_status._M_load(memory_order_acquire) == _Status::__ready)
return future_status::ready;
if (_M_is_deferred_future())
return future_status::deferred;
// Don't wait unless the relative time is greater than zero.
if (__rel > __rel.zero()
&& _M_status._M_load_when_equal_for(_Status::__ready,
memory_order_acquire,
__rel))
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 2100. timed waiting functions must also join
// This call is a no-op by default except on an async future,
// in which case the async thread is joined. It's also not a
// no-op for a deferred future, but such a future will never
// reach this point because it returns future_status::deferred
// instead of waiting for the future to become ready (see
// above). Async futures synchronize in this call, so we need
// no further synchronization here.
_M_complete_async();
return future_status::ready;
}
return future_status::timeout;
}
Исходная версия ox55ff, :
Я спросил как проверить не блокируя основной поток, вы привели пример как блокировать «на какой-то совсем короткий интервал времени»
Если у фьючи уже есть результат, то блокировки не будет. Если время ожидания равно нулю, то блокировки не будет. Ты не разобрался как работают фьючи, но обвиняешь людей, которые пытаются тебе помочь. Какого эффекта, ты хочешь добится? Чтобы в твоей теме остались одни тролли, а понимающие люди забили на тебя?
future_status
wait_for(const chrono::duration<_Rep, _Period>& __rel)
{
// First, check if the future has been made ready. Use acquire MO
// to synchronize with the thread that made it ready.
if (_M_status._M_load(memory_order_acquire) == _Status::__ready)
return future_status::ready;
if (_M_is_deferred_future())
return future_status::deferred;
// Don't wait unless the relative time is greater than zero.
if (__rel > __rel.zero()
&& _M_status._M_load_when_equal_for(_Status::__ready,
memory_order_acquire,
__rel))
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 2100. timed waiting functions must also join
// This call is a no-op by default except on an async future,
// in which case the async thread is joined. It's also not a
// no-op for a deferred future, but such a future will never
// reach this point because it returns future_status::deferred
// instead of waiting for the future to become ready (see
// above). Async futures synchronize in this call, so we need
// no further synchronization here.
_M_complete_async();
return future_status::ready;
}
return future_status::timeout;
}