3 ms·
std::condition_variable existed since c++11, so std::latch must provide some benefit beyond it.
by Thorrez 6y ago
std::condition_variable existed since c++11, so std::latch must provide some benefit beyond it.
- DSingularity 6y agoPerhaps differentiation is justified as program semantics can be captured to allow optimizations in runtimes. For example, condition variable to wait for events which can be delayed vs latched to wait for arrival of running threads to a point of execution. Runtime should handle each uniquely.
- PaulDavisThe1st 6y agoThe semantics of latch are a little simpler, which leaves room for a lighter weight implementation than is typically associated with condition variables. Barriers are closer, but also have slightly simpler semantics, again allowing for a potentially lighter weight implementation. But the semantics are not sufficiently different as to allow for any notably new use cases/code flow, certainly not from the examples I've seen. Every one of them could have been written using condition variables at any point in the last 30 years and would look almost indistinguishable.