Ticket #6130: cvt.cc

File cvt.cc, 571 bytes (added by Gennady Proskurin <gpr@…>, 11 years ago)
Line 
1#include <boost/thread.hpp>
2#include <assert.h>
3#include <iostream>
4#include <stdlib.h>
5#include <unistd.h>
6
7boost::mutex mtx;
8boost::condition_variable cv;
9
10int main()
11{
12 while(1) {
13 for (int i=0; i<3; ++i) {
14 const time_t wait_time = ::time(0)+1;
15
16 boost::mutex::scoped_lock lk(mtx);
17 const bool res = cv.timed_wait(lk, boost::posix_time::from_time_t(wait_time));
18 const time_t end_time = ::time(0);
19 assert(end_time >= wait_time);
20 std::cerr << "OK\n";
21 }
22 const long s = random() % 100000;
23 std::cerr << "switch, sleep " << s << " ms\n";
24 usleep(s);
25 }
26}