| 1 | // Copyright (C) 2010 Vicente Botet |
|---|---|
| 2 | // |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | #define BOOST_THREAD_VERSION 2 |
| 7 | |
| 8 | #include <boost/thread/thread_only.hpp> |
| 9 | #include <boost/date_time/posix_time/posix_time_io.hpp> |
| 10 | #include <assert.h> |
| 11 | #include <iostream> |
| 12 | #include <stdlib.h> |
| 13 | #if defined(BOOST_THREAD_PLATFORM_PTHREAD) |
| 14 | #include <unistd.h> |
| 15 | #endif |
| 16 | |
| 17 | boost::mutex mtx; |
| 18 | boost::condition_variable cv; |
| 19 | |
| 20 | using namespace boost::posix_time; |
| 21 | using namespace boost::gregorian; |
| 22 | int main() |
| 23 | { |
| 24 | #if defined(BOOST_THREAD_PLATFORM_PTHREAD) |
| 25 | |
| 26 | for (int i=0; i<3; ++i) |
| 27 | { |
| 28 | const time_t now_time = ::time(timer: 0); |
| 29 | const time_t wait_time = now_time+1; |
| 30 | time_t end_time; |
| 31 | assert(now_time < wait_time); |
| 32 | |
| 33 | boost::unique_lock<boost::mutex> lk(mtx); |
| 34 | //const bool res = |
| 35 | (void)cv.timed_wait(m&: lk, abs_time: from_time_t(t: wait_time)); |
| 36 | end_time = ::time(timer: 0); |
| 37 | std::cerr << "now_time ="<< now_time << " \n"; |
| 38 | std::cerr << "end_time ="<< end_time << " \n"; |
| 39 | std::cerr << "wait_time="<< wait_time << " \n"; |
| 40 | std::cerr << "now_time ="<< from_time_t(t: now_time) << " \n"; |
| 41 | std::cerr << "end_time ="<< from_time_t(t: end_time) << " \n"; |
| 42 | std::cerr << "wait_time="<< from_time_t(t: wait_time) << " \n"; |
| 43 | std::cerr << end_time - wait_time << " \n"; |
| 44 | assert(end_time >= wait_time); |
| 45 | std::cerr << " OK\n"; |
| 46 | } |
| 47 | #endif |
| 48 | return 0; |
| 49 | } |
| 50 |
