condition_variable
std::mutex m;
std::condition_variable cv;
bool data_ready = false;
void producer() {
while (true) {
std::lock_guard<std::mutex> lock(m);
data_ready = true;
cv.notify_one();
}
}
void consumer() {
while (true) {
std::unique_lock<std::mutex> lock(m);
cv.wait(lock, [] { return data_ready; });
// Consume data
data_ready = false;
}
}