Namespaces
Variants
Views
Actions

std::latch

From cppreference.com
< cpp‎ | thread
 
 
Thread support library
Threads
(C++11)
(C++20)
(C++20)
this_thread namespace
(C++11)
(C++11)
(C++11)
Mutual exclusion
(C++11)
Generic lock management
(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
(C++11)
(C++11)
Condition variables
(C++11)
Semaphores
Latches and barriers
latch
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
(C++11)
 
 
Defined in header <latch>
class latch;
(since C++20)

The latch class is a downward counter of type ptrdiff_t which can be used to synchronize threads. The value of the counter is initialized on creation. Threads may block on the latch until the counter is decremented to zero. There is no possibility to increase or reset the counter, which makes the latch a single-use barrier.

Concurrent invocations of the member functions of latch, except for the destructor, do not introduce data races.

Unlike std::barrier, std::latch can be decremented by a participating thread more than once.

Contents

[edit] Member functions

constructs a latch
(public member function) [edit]
destroys the latch
(public member function) [edit]
operator=
[deleted]
latch is not assignable
(public member function)
decrements the counter in a non-blocking manner
(public member function) [edit]
tests if the internal counter equals zero
(public member function) [edit]
blocks until the counter reaches zero
(public member function) [edit]
decrements the counter and blocks until it reaches zero
(public member function) [edit]
Constants
[static]
the maximum value of counter supported by the implementation
(public static member function) [edit]

[edit] Example

[edit] See also

(C++20)
reusable thread barrier
(class template) [edit]