// Khong mot dong nao cua vslam. Chi std::mutex + condition_variable, dung // khuon mau y het Channel: mot luong cho co vi ngu, mot luong dat co. #include #include #include #include std::mutex mu; std::condition_variable cv; bool flag = false; int main() { { std::lock_guard lk(mu); } // giong MakeReader: khoa roi tha std::thread th([]{ std::unique_lock lk(mu); cv.wait_for(lk, std::chrono::seconds(5), []{ return flag; }); }); std::this_thread::sleep_for(std::chrono::milliseconds(50)); { std::lock_guard lk(mu); flag = true; } // giong Close cv.notify_all(); th.join(); std::puts("xong"); return 0; }