#include #include #include #include #include boost::mutex mtx; boost::condition_variable cv; int main() { while(1) { for (int i=0; i<3; ++i) { const time_t wait_time = ::time(0)+1; boost::mutex::scoped_lock lk(mtx); const bool res = cv.timed_wait(lk, boost::posix_time::from_time_t(wait_time)); const time_t end_time = ::time(0); assert(end_time >= wait_time); std::cerr << "OK\n"; } const long s = random() % 100000; std::cerr << "switch, sleep " << s << " ms\n"; usleep(s); } }