Namespaces
Variants

std::counting_semaphore<LeastMaxValue>:: try_acquire_for

From cppreference.net
Concurrency support library
Threads
(C++11)
(C++20)
this_thread namespace
(C++11)
(C++11)
Cooperative cancellation
Mutual exclusion
Generic lock management
Condition variables
(C++11)
Semaphores
Latches and Barriers
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
Safe reclamation
Hazard pointers
Atomic types
(C++11)
(C++20)
Initialization of atomic types
(C++11) (deprecated in C++20)
(C++11) (deprecated in C++20)
Memory ordering
(C++11) (deprecated in C++26)
Free functions for atomic operations
Free functions for atomic flags
template < class Rep, class Period >
bool try_acquire_for ( const std:: chrono :: duration < Rep, Period > & rel_time ) ;
(C++20 起)

尝试在内部计数器大于 1 时原子性地将其递减 1 ;否则会阻塞直到计数器大于 0 且能成功递减内部计数器,或超过 rel_time 持续时间。

目录

前置条件

(无)

参数

rel_time - 函数必须等待其失败的最短持续时间

返回值

true 表示成功递减内部计数器,否则返回 false

异常

可能抛出 std::system_error 或与超时相关的异常。

注释

实际上,该函数可能需要比 rel_time 更长的时间才会失败。

参阅

递增内部计数器并解除获取者的阻塞
(公开成员函数)
递减内部计数器或在可递减前保持阻塞
(公开成员函数)
尝试非阻塞地递减内部计数器
(公开成员函数)
尝试递减内部计数器,阻塞直至指定时间点
(公开成员函数)