C++ Condition Variables - The Basics 1 ▲ Andrew's Blog 1 hour ago · Tech · hide · 0 comments Trains need careful marshalling, your threads are the same. I apologize for this illustration, it is bad even by my standards. In my defense, I drew it on an airplane. Condition variables (CVs) are supposed to be the easy-to-use, hard-to-mess-up synchronization primitive in C++. There are still plenty of way to mess them up, some subtle enough that I often encounter issues in production code. This article is a gentle walk through some of the common errors. Key Takeaways Condition Variables are are “edge-triggered”, not “level-triggered” You almost certainly want to use condition_variable::lock() with a predicate. Anything else is a code smell. Using a std::atomic flag in the predicate is a code smell. The same mutex referenced in condition_variable::lock() must be used to protect any variables used in the predicate. Other primitives exist and may be easier or more suited to your objective. Edge-Triggered vs Level-Triggered These are terms from electrical engineering that I am… No comments yet. Log in to reply on the Fediverse. Comments will appear here.