test_9079_a.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright (C) 2013 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. // A
  6. //#include <boost/log/trivial.hpp>
  7. #include <boost/chrono.hpp>
  8. #include <boost/thread.hpp>
  9. #include <boost/thread/condition_variable.hpp>
  10. //#if !defined(BOOST_NO_CXX11_ALIGNAS)
  11. //#error
  12. //# define BOOST_ALIGNMENT2(x) alignas(x)
  13. //#elif defined(_MSC_VER)
  14. //#error
  15. //# define BOOST_ALIGNMENT2(x) __declspec(align(x))
  16. //#elif defined(__GNUC__)
  17. //#error
  18. //# define BOOST_ALIGNMENT(x) __attribute__ ((__aligned__(x)))
  19. //#else
  20. //#error
  21. //# define BOOST_NO_ALIGNMENT2
  22. //# define BOOST_ALIGNMENT2(x)
  23. //#endif
  24. typedef boost::chrono::high_resolution_clock Clock;
  25. typedef Clock::time_point TimePoint;
  26. inline TimePoint real_time_now()
  27. {
  28. return Clock::now();
  29. }
  30. int main()
  31. {
  32. using namespace boost::chrono;
  33. boost::condition_variable m_task_spawn_condition;
  34. boost::mutex main_thread_mutex;
  35. boost::unique_lock < boost::mutex > main_thread_lock(main_thread_mutex);
  36. //BOOST_LOG_TRIVIAL(info) << "[TaskScheduler::run_and_wait] Scheduling loop - BEGIN";
  37. //for (;;)
  38. {
  39. static const milliseconds TIME_BACK = milliseconds(1);
  40. m_task_spawn_condition.wait_until(
  41. main_thread_lock,
  42. real_time_now() - TIME_BACK); // wait forever
  43. m_task_spawn_condition.wait_for( main_thread_lock, - TIME_BACK ); // same problem
  44. //BOOST_LOG_TRIVIAL(trace) << "TICK";
  45. }
  46. }