.. _libcudacxx-extended-api-synchronization-latch: cuda::latch =============== Defined in header ````: .. code:: cpp template class cuda::latch; The class template ``cuda::latch`` is an extended form of `cuda::std::latch `_ takes an additional :ref:`cuda::thread_scope ` argument. It has the same interface and semantics as `cuda::std::latch `_. Concurrency Restrictions ------------------------ An object of type ``cuda::latch`` or `cuda::std::latch `_ shall not be accessed concurrently by CPU and GPU threads unless: - it is in unified memory and the `concurrentManagedAccess property `_ is 1, or - it is in CPU memory and the `hostNativeAtomicSupported property `_ is 1. Note, for objects of scopes other than ``cuda::thread_scope_system`` this is a data-race, and therefore also prohibited regardless of memory characteristics. Under CUDA Compute Capability 6 (Pascal) or prior, an object of type ``cuda::latch`` or `cuda::std::latch `_ may not be used. Implementation-Defined Behavior ------------------------------- For each :ref:`cuda::thread_scope ` ``S``, the value of ``cuda::latch::max()`` is as follows: .. list-table:: :widths: 50 50 :header-rows: 0 * - :ref:`cuda::thread_scope ` ``S`` - ``cuda::latch::max()`` * - Any thread scope - ``cuda::std::numeric_limits::max()`` Example ------- .. code:: cuda #include __global__ void example_kernel() { // This latch is suitable for all threads in the system. cuda::latch a(10); // This latch has the same type as the previous one (`a`). cuda::std::latch b(10); // This latch is suitable for all threads on the current processor (e.g. GPU). cuda::latch c(10); // This latch is suitable for all threads in the same thread block. cuda::latch d(10); } `See it on Godbolt `_