std::unique_lock::try_lock_for
来自cppreference.com
< cpp | thread | unique lock
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
template< class Rep, class Period > bool try_lock_for( const std::chrono::duration<Rep,Period>& timeout_duration ); |
(C++11 起) | |
试图锁定相关联的互斥体。已过或阻塞,直到指定
timeout_duration
获得该锁,以先到者为准。在成功锁定获取回报true,否则返回false。可能会阻止长于timeout_duration
.原文:
Tries to lock the associated mutex. Blocks until specified
timeout_duration
has elapsed or the lock is acquired, whichever comes first. On successful lock acquisition returns true, otherwise returns false. May block for longer than timeout_duration
.有效地调用mutex()->try_lock_for(timeout_duration)
原文:
Effectively calls mutex()->try_lock_for(timeout_duration)
std::system_error被抛出,如果没有相关的互斥或如果该互斥锁已经锁定.
原文:
std::system_error is thrown if there is no associated mutex or if the mutex is already locked.
目录 |
[编辑] 参数
timeout_duration | - | 阻塞最长持续时间
|
[编辑] 返回值
true如果已成功获取互斥体的所有权,false否则.
原文:
true if the ownership of the mutex has been acquired successfully, false otherwise.
[编辑] 例外
- mutex()->try_lock_for(timeout_duration)抛出的任何异常原文:Any exceptions thrown by mutex()->try_lock_for(timeout_duration)
- 如果没有相关的互斥体,std::system_error的错误代码std::errc::operation_not_permitted原文:If there is no associated mutex, std::system_error with an error code of std::errc::operation_not_permitted
- 如果互斥锁已被锁定,std::system_error的std::errc::resource_deadlock_would_occur的错误代码原文:If the mutex is already locked, std::system_error with an error code of std::errc::resource_deadlock_would_occur
[编辑] 示例
本章尚未完成 原因:暂无示例 |
[编辑] 另请参阅
locks the associated mutex (公共成员函数) | |
试图锁定相关联的互斥量,退货,如果该互斥锁不可用 原文: tries to lock the associated mutex, returns if the mutex is not available (公共成员函数) | |
试图锁定相关的 TimedLockable 互斥的回报,如果互斥体已经不可用,直到指定的时间点已经达到 原文: tries to lock the associated TimedLockable mutex, returns if the mutex has been unavailable until specified time point has been reached (公共成员函数) | |
解锁相关的互斥 (公共成员函数) |