Condvars and atomics do not mix

In this post, the author discusses how to use std::condition_variable in C++ and the potential pitfalls that arise when mixing atomics with condition variables. The author provides code examples and explains the importance of ensuring clean termination of threads. They highlight a race condition that can occur when utilizing std::atomic and propose a solution by using a mutex in the destructor instead. The author emphasizes the need for a careful audit of code when mixing atomics and condition variables to prevent potential issues. They stress the difference between “physical” and “logical” atomicity and the importance of maintaining system invariants.

https://zeux.io/2024/03/23/condvars-atomic/

To top