std::unique_lock::try_lock_for

template< class Rep, class Period >
bool try_lock_for( const std::chrono::duration<Rep,Period>& timeout_duration );
(C++11 起)

尝试锁定关联互斥。阻塞直至经过指定的 timeout_duration 或获得锁,之先到来者。成功获得锁时返回 true ,否则返回 false 。等效地调用 mutex()->try_lock_for(timeout_duration)

由于调度或资源争议延迟,此函数可能阻塞长于 timeout_duration

标准建议用稳定时钟度量时长。若实现用系统时钟代替,则等待时间亦可能对时钟调节敏感。

若无关联互斥或已锁定互斥则抛出 std::system_error

目录

参数

timeout_duration - 要阻塞的最大时长

返回值

若成功获得得到互斥锁有权则为 true ,否则为 false

异常

示例

参阅

锁定关联互斥
(公开成员函数)
尝试锁定关联互斥,若互斥不可用则返回
(公开成员函数)
尝试锁定关联可定时锁 (TimedLockable) 互斥,若抵达指定时间点互斥仍不可用则返回
(公开成员函数)
解锁关联互斥
(公开成员函数)

版本历史

  • (当前 | 先前 2017年8月26日 (六) 09:09Fruderica讨论 | 贡献. . (1,633字节) (-1,117). . (撤销)
  • 当前 | 先前 2014年10月26日 (日) 18:11P12bot讨论 | 贡献 . . (2,750字节) (0). . (Fix some translations) (撤销)
  • 当前 | 先前 2013年7月2日 (二) 11:37P12bot讨论 | 贡献 . . (2,750字节) (-124). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 17:45P12bot讨论 | 贡献 . . (2,874字节) (+345). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月27日 (六) 11:34P12讨论 | 贡献 . . (2,529字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 06:00TranslationBot讨论 | 贡献. . (2,529字节) (-73). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 03:32P12讨论 | 贡献 . . (2,602字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (2,602字节) (+2,602). . (Translated from the English version using Google Translate)