首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::recursive_timed_mutex::try_lock_until

template< class Clock, class Duration > bool try_lock_until( const std::chrono::time_point<Clock,Duration>& timeout_time );

?

(since C++11)

试图锁定互斥体。块,直到指定timeout_time已到达或已获得锁,两者以第一位为准。关于成功锁定获取返回true,否则返回false...

如果timeout_time已传递,此函数的行为如下try_lock()...

钟系在timeout_time使用,这意味着考虑到时钟的调整。因此,块的最大持续时间可能小于或超过timeout_time - Clock::now()在呼叫时,取决于调整的方向。该函数也可能阻塞时间超过之后。timeout_time由于调度或资源争用延迟已到达。

和...一样try_lock(),则允许此函数伪造失败并返回。false即使互斥锁之前没有被任何其他线程锁定。timeout_time...

优先unlock()对同一个互斥体的操作同步性中定义的28名ASstd::memory_order%29如果返回此操作true...

线程可以调用try_lock_until在递归互斥体上重复。成功呼叫try_lock_until增加所有权计数:只有在线程进行匹配次数的调用之后,互斥锁才会释放。unlock...

所有权的最大级别未指定。打电话给try_lock_until会回来false如果超过此数字。

参数

timeout_time

-

maximum time point to block until

返回值

true如果成功获取锁,则为false...

例外

任何由时钟、时间引发的异常[医]在执行%28时钟、时间点和标准库提供的持续时间期间,不要抛出%29。

这个例子显示了一个10秒的块。

二次

代码语言:javascript
复制
#include <thread>
#include <iostream>
#include <chrono>
#include <mutex>
 
std::recursive_timed_mutex test_mutex;
 
void f()
{
    auto now=std::chrono::steady_clock::now();
    test_mutex.try_lock_until(now + std::chrono::seconds(10));
    std::cout << "hello world\n";
}
 
int main()
{
    std::lock_guard<std::recursive_timed_mutex> l(test_mutex);
    std::thread t(f);
    t.join();
}

二次

另见

lock

locks the mutex, blocks if the mutex is not available (public member function)

try_lock

tries to lock the mutex, returns if the mutex is not available (public member function)

try_lock_for

tries to lock the mutex, returns if the mutex has beenunavailable for the specified timeout duration (public member function)

unlock

unlocks the mutex (public member function)

c MTX文件[医]时间锁

代码语言:txt
复制
 ? cppreference.com

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com