wait_for()超时之后,是继续阻塞;还是执行后续语句 ?

std::unique_lock<std::mutex>my_lc(my_mutex);
my_cond.wait_for(my_lc, std::chrono::milliseconds(10000));

小唯快跑啊
浏览 121回答 2
2回答

慕姐8265434

根据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)&nbsp;return pred();//超时后调用谓词并返回结果,true or falsereturn true;&nbsp;

犯罪嫌疑人X

如果没有获取到,仍然处于阻塞状态
打开App,查看更多内容
随时随地看视频慕课网APP