C++
线程支持 | Thread support

std::unique_lock::try_lock

性病::独特[医]锁::试一试[医]锁

bool try_lock((since C++11)

试图锁定相关的互斥锁而不阻塞。有效呼叫mutex()->try_lock()...

std::system_error如果没有关联的互斥对象,或者互斥对象已被std::unique_lock...

参数

%280%29

返回值

true如果互斥体的所有权已经成功获得,false否则。

例外

  • 引发的任何异常mutex()->try_lock()%28Mutex类型不提交try_lock,但这是一种习俗Lockable%29

  • 如果没有关联的互斥,std::system_error错误代码为std::errc::operation_not_permitted

  • 如果互斥锁已被std::unique_lock,,,std::system_error错误代码为std::errc::resource_deadlock_would_occur

另见

locklocks the associated mutex (public member function)
try_lock_forattempts to lock the associated TimedLockable mutex, returns if the mutex has been unavailable for the specified time duration (public member function)
try_lock_untiltries to lock the associated TimedLockable mutex, returns if the mutex has been unavailable until specified time point has been reached (public member function)
unlockunlocks the associated mutex (public member function)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/线程/UNIQUE[医]锁/试[医]锁