time.qbk 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. [/
  2. (C) Copyright 2007-8 Anthony Williams.
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. ]
  7. [section:time Time Requirements]
  8. As of Boost 1.50.0, the __boost_thread__ library uses Boost.Chrono library for all operations that require a
  9. time out as defined in the standard c++11. These include (but are not limited to):
  10. * `boost::this_thread::__sleep_for`
  11. * `boost::this_thread::__sleep_until`
  12. * `boost::__thread::__try_join_for`
  13. * `boost::__thread::__try_join_until`
  14. * `boost::__condition_variable::__wait_for`
  15. * `boost::__condition_variable::__wait_until`
  16. * `boost::__condition_variable_any::__cvany_wait_for`
  17. * `boost::__condition_variable_any::__cvany_wait_until`
  18. * `__TimedLockable::__try_lock_for`
  19. * `__TimedLockable::__try_lock_until`
  20. [section:deprecated Deprecated]
  21. The time related functions introduced in Boost 1.35.0, using the [link date_time Boost.Date_Time] library are deprecated. These include (but are not limited to):
  22. * __sleep__
  23. * __timed_join__
  24. * __cond_timed_wait__
  25. * __timed_lock_ref__
  26. For the overloads that accept an absolute time parameter, an object of type [link thread.time.deprecated.system_time `boost::system_time`] is
  27. required. Typically, this will be obtained by adding a duration to the current time, obtained with a call to [link
  28. thread.time.deprecated.get_system_time `boost::get_system_time()`]. e.g.
  29. boost::system_time const timeout=boost::get_system_time() + boost::posix_time::milliseconds(500);
  30. extern bool done;
  31. extern boost::mutex m;
  32. extern boost::condition_variable cond;
  33. boost::unique_lock<boost::mutex> lk(m);
  34. while(!done)
  35. {
  36. if(!cond.timed_wait(lk,timeout))
  37. {
  38. throw "timed out";
  39. }
  40. }
  41. For the overloads that accept a ['TimeDuration] parameter, an object of any type that meets the [link
  42. date_time.posix_time.time_duration Boost.Date_Time Time Duration requirements] can be used, e.g.
  43. boost::this_thread::sleep(boost::posix_time::milliseconds(25));
  44. boost::mutex m;
  45. if(m.timed_lock(boost::posix_time::nanoseconds(100)))
  46. {
  47. // ...
  48. }
  49. [section:system_time Typedef `system_time`]
  50. #include <boost/thread/thread_time.hpp>
  51. typedef boost::posix_time::ptime system_time;
  52. See the documentation for [link date_time.posix_time.ptime_class `boost::posix_time::ptime`] in the Boost.Date_Time library.
  53. [endsect]
  54. [section:get_system_time Non-member function `get_system_time()`]
  55. #include <boost/thread/thread_time.hpp>
  56. system_time get_system_time();
  57. [variablelist
  58. [[Returns:] [The current time.]]
  59. [[Throws:] [Nothing.]]
  60. ]
  61. [endsect]
  62. [endsect]
  63. [endsect]