std::shared_lock::try_lock_for
template< class Rep, class Period > bool try_lock_for( const std::chrono::duration<Rep,Period>& timeout_duration ); | | (since C++14) |
|---|
尝试将关联的互斥锁在共享模式下。块,直到指定timeout_duration已过或已取得锁,以第一位为准。关于成功锁定获取返回true,否则返回false.有效地打电话mutex()->try_lock_shared_for(timeout_duration)...
用一个稳定的时钟来测量持续时间。此函数的阻塞时间可能超过timeout_duration由于调度或资源争用延迟。
std::system_error如果没有关联的互斥对象,或者互斥对象已经锁定,则引发。
参数
timeout_duration | - | maximum duration to block for |
|---|
返回值
true如果互斥体的所有权已经成功获得,false否则。
例外
- 引发的任何异常
mutex()->try_lock_shared_for(timeout_duration)
- 如果没有关联的互斥,
std::system_error错误代码为std::errc::operation_not_permitted
- 如果互斥锁已经锁定,
std::system_error错误代码为std::errc::resource_deadlock_would_occur
例
另见
try_lock_for | attempts to lock the associated TimedLockable mutex, returns if the mutex has been unavailable for the specified time duration (public member function of std::unique_lock) |
|---|---|
lock | locks the associated mutex (public member function) |
try_lock | tries to lock the associated mutex (public member function) |
try_lock_until | tries to lock the associated mutex, until a specified time point (public member function) |
unlock | unlocks the associated mutex (public member function) |
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

