Skip to content

Latch

Category: Synchronization · Status: stub · Lessons: chapter 04, Waiting for each other (planned)

One line: A one-shot gate: tasks wait on it until a set number of other tasks have each signalled, then every waiter proceeds and the gate stays open.

Also called: CountDownLatch, std::latch, CountdownEvent.

How it connects

flowchart LR
  n_barrier["Barrier"]
  n_latch["Latch"]
  n_synchronization["Synchronization"]
  n_barrier ---|vs| n_latch
  n_latch -->|is a| n_synchronization
  classDef center stroke-width:3px
  class n_latch center
  classDef outside stroke-dasharray: 4 3
  class n_barrier,n_synchronization outside

In each language

Go sync.WaitGroup, a counting semaphore typically used to wait for a group of goroutines to finish
C++ std::latch (C++20), a downward counter that threads can block on until it reaches zero
Java CountDownLatch: a one-shot phenomenon, the count cannot be reset
Python No counted latch; threading.Event is a flag that wait blocks on until it is set
C# CountdownEvent is signaled when its count reaches zero

Where to read more