test_6130.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #define BOOST_THREAD_VERSION 2
  6. #include <boost/thread/thread_only.hpp>
  7. #include <boost/date_time/posix_time/posix_time_io.hpp>
  8. #include <assert.h>
  9. #include <iostream>
  10. #include <stdlib.h>
  11. #if defined(BOOST_THREAD_PLATFORM_PTHREAD)
  12. #include <unistd.h>
  13. #endif
  14. boost::mutex mtx;
  15. boost::condition_variable cv;
  16. using namespace boost::posix_time;
  17. using namespace boost::gregorian;
  18. int main()
  19. {
  20. #if defined(BOOST_THREAD_PLATFORM_PTHREAD)
  21. for (int i=0; i<3; ++i)
  22. {
  23. const time_t now_time = ::time(0);
  24. const time_t wait_time = now_time+1;
  25. time_t end_time;
  26. assert(now_time < wait_time);
  27. boost::unique_lock<boost::mutex> lk(mtx);
  28. //const bool res =
  29. (void)cv.timed_wait(lk, from_time_t(wait_time));
  30. end_time = ::time(0);
  31. std::cerr << "now_time =" << now_time << " \n";
  32. std::cerr << "end_time =" << end_time << " \n";
  33. std::cerr << "wait_time=" << wait_time << " \n";
  34. std::cerr << "now_time =" << from_time_t(now_time) << " \n";
  35. std::cerr << "end_time =" << from_time_t(end_time) << " \n";
  36. std::cerr << "wait_time=" << from_time_t(wait_time) << " \n";
  37. std::cerr << end_time - wait_time << " \n";
  38. assert(end_time >= wait_time);
  39. std::cerr << " OK\n";
  40. }
  41. #endif
  42. return 0;
  43. }