std::unique_lock<std::mutex>my_lc(my_mutex);my_cond.wait_for(my_lc, std::chrono::milliseconds(10000));
2 回答
慕姐8265434
TA贡献1813条经验 获得超2个赞
根据c++源码看,超时后会退出阻塞,继续执行后续代码
template <class Rep, class Period>
cv_status wait_for (unique_lock<mutex>& lck,
const chrono::duration<Rep,Period>& rel_time);
return wait_until (lck,chrono::steady_clock::now() + rel_time, std::move(pred));
带谓词
template <class Rep, class Period, class Predicate>
bool wait_for (unique_lock<mutex>& lck,
const chrono::duration<Rep,Period>& rel_time, Predicate pred);
while (!pred())
if (wait_until(lck,abs_time) == cv_status::timeout)
return pred();//超时后调用谓词并返回结果,true or false
return true;
- 2 回答
- 0 关注
- 120 浏览
添加回答
举报
0/150
提交
取消