From the documentation is pretty clear that the difference between them is that std::barrier
can be used more than once and std::latch
can only be used once.
That sounds to me like std::latch
is simply a special case of std::barrier
that adds a limitation instead of a feature. On top of that the documentation says that a call to count_down
with an n
greater than the internal counter is undefined behavior, so this limitation has to be enforced programatically.
So why do we need std::latch
?
My only guess is that it is possible to implement std::latch
differently at the hardware level in a way that improves performance.
What is the reason?