Structs
Counting latches are used to implement scopes. They track a counter. Unlike
other latches, calling
set()
does not necessarily make the latch be
considered set()
; instead, it just decrements the counter. The latch is
only “set” (in the sense thatis_set()
returns true) once the counter reaches zero.A Latch starts as false and eventually becomes true. You can block until
it becomes true.
Spin latches are the simplest, most efficient kind, but they do not support
a
wait()
operation. They just have a boolean flag that becomes true when
set()
is called.Traits
We define various kinds of latches, which are all a primitive signaling
mechanism. A latch starts as false. Eventually someone calls
set()
and
it becomes true. You can test if it has been set by calling is_set()
.