Hacker News new | past | comments | ask | show | jobs | submit login

Glib::Cond has existed for longer, and is just a wrapper around pthread condition variables that go back to the 1980s.

Several other C++ libraries also provided condition variables, which latches are a variant of, along with barriers and flex_latches.




std::condition_variable existed since c++11, so std::latch must provide some benefit beyond it.


The 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.


Perhaps 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.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: