[#BloombergLP-bslmt-Latch]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslmt.adoc[bslmt]::Latch
:relfileprefix: ../../
:mrdocs:

This class defines a thread synchronization mechanism that allows one or more threads to wait until a certain number of operations have been performed by other threads&period;

== Synopsis

Declared in `&lt;bslmt&lowbar;latch&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class Latch;
----

== Enums

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bslmt/Latch/_04enum.adoc[`Unnamed enum`] 
| Status codes for timed wait operations&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bslmt/Latch/2constructor-00.adoc[`Latch`]         [.small]#[constructor]#
| Constructors
| xref:BloombergLP/bslmt/Latch/2destructor.adoc[`&#126;Latch`] [.small]#[destructor]#
| Destroy this latch&period; The behavior is undefined if any threads are waiting on this latch&period;
| xref:BloombergLP/bslmt/Latch/arrive.adoc[`arrive`] 
| Decrement the number of events that this latch is waiting for by 1, and if the resulting number of events is 0 release any waiting threads&period; The behavior is undefined unless the sum of all events that have arrived at this latch does not exceed the count with which it was initialized&period; Note that the initial count of events is supplied at construction&period;
| xref:BloombergLP/bslmt/Latch/arriveAndWait.adoc[`arriveAndWait`] 
| Decrement the number of events that this latch is waiting for by 1, and if the resulting number of events is 0 release any waiting threads&semi; otherwise, block until the required number of events has been reached&period; The behavior is undefined unless the sum of all events that have arrived at this latch does not exceed the count with which it was initialized&period; Note that the initial count of events is supplied at construction&period; Also note that this method is equivalent to the following sequence&colon; &grave; arrive()&semi; wait()&semi; &grave;
| xref:BloombergLP/bslmt/Latch/clockType.adoc[`clockType`] 
| Return the clock type used for timeouts&period;
| xref:BloombergLP/bslmt/Latch/countDown.adoc[`countDown`] 
| Decrement the number of events that this latch is waiting for by the specified `numEvents`, and if the resulting number of events is 0 release any waiting threads&period; The behavior is undefined unless `numEvents &gt; 0` and the sum of all events that have arrived at this latch does not exceed the count with which it was initialized&period; Note that the initial count of events is supplied at construction&period;
| xref:BloombergLP/bslmt/Latch/currentCount.adoc[`currentCount`] 
| Return the current number of events for which this latch is waiting&period; Note that this method is provided primarily for debugging purposes (i&period;e&period;, its intended use is not as a synchronization mechanism), and can be used only as an upper bound for the current count without other external state information&period;
| xref:BloombergLP/bslmt/Latch/timedWait-07.adoc[`timedWait`] 
| `timedWait` overloads
| xref:BloombergLP/bslmt/Latch/tryWait.adoc[`tryWait`] 
| Return `true` if this latch has already been released (i&period;e&period;, the number of events the latch is waiting on is 0), and `false` otherwise&period; This method does not block&period; Note that a return value of `true` indicates a permanent state change (the latch has released and will never be un&hyphen;released), but a return value of `false` is ephemeral and cannot typically be acted upon without additional external state information&period; Also note that a return value of `true` does not guarantee this object is safe to destroy&period;
| xref:BloombergLP/bslmt/Latch/wait.adoc[`wait`] 
| Block until the number of events that this latch is waiting for reaches 0&period; Note that completion of this method does not guarantee this object is safe to destroy&period;
|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
