2 回答

TA貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個(gè)贊
根據(jù)c++源碼看,超時(shí)后會(huì)退出阻塞,繼續(xù)執(zhí)行后續(xù)代碼
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();//超時(shí)后調(diào)用謂詞并返回結(jié)果,true or false
return true;
- 2 回答
- 0 關(guān)注
- 152 瀏覽
添加回答
舉報(bào)