1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<head> 4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 5<title>Time Requirements</title> 6<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css"> 7<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 8<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset"> 9<link rel="up" href="../thread.html" title="Chapter 39. Thread 4.8.0"> 10<link rel="prev" href="parallel.html" title="Parallel - Fork-Join -- EXPERIMENTAL"> 11<link rel="next" href="emulations.html" title="Emulations"> 12</head> 13<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 14<table cellpadding="2" width="100%"><tr> 15<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td> 16<td align="center"><a href="../../../index.html">Home</a></td> 17<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td> 18<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 19<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 20<td align="center"><a href="../../../more/index.htm">More</a></td> 21</tr></table> 22<hr> 23<div class="spirit-nav"> 24<a accesskey="p" href="parallel.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../thread.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="emulations.html"><img src="../../../doc/src/images/next.png" alt="Next"></a> 25</div> 26<div class="section"> 27<div class="titlepage"><div><div><h2 class="title" style="clear: both"> 28<a name="thread.time"></a><a class="link" href="time.html" title="Time Requirements">Time Requirements</a> 29</h2></div></div></div> 30<div class="toc"><dl class="toc"><dt><span class="section"><a href="time.html#thread.time.deprecated">Deprecated</a></span></dt></dl></div> 31<p> 32 As of Boost 1.50.0, the <span class="bold"><strong>Boost.Thread</strong></span> library 33 uses Boost.Chrono library for all operations that require a time out as defined 34 in the standard c++11. These include (but are not limited to): 35 </p> 36<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 37<li class="listitem"> 38 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><a class="link" href="thread_management.html#thread.thread_management.this_thread.sleep_for" title="Non-member function sleep_for()"><code class="computeroutput"><span class="identifier">sleep_for</span></code></a></code> 39 </li> 40<li class="listitem"> 41 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><a class="link" href="thread_management.html#thread.thread_management.this_thread.sleep_until" title="Non-member function sleep_until()"><code class="computeroutput"><span class="identifier">sleep_until</span></code></a></code> 42 </li> 43<li class="listitem"> 44 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">thread</span></code></a><span class="special">::</span><a class="link" href="thread_management.html#thread.thread_management.thread.try_join_for" title="Member function try_join_for() EXTENSION"><code class="computeroutput"><span class="identifier">try_join_for</span></code></a></code> 45 </li> 46<li class="listitem"> 47 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><a class="link" href="thread_management.html#thread.thread_management.thread" title="Class thread"><code class="computeroutput"><span class="identifier">thread</span></code></a><span class="special">::</span><a class="link" href="thread_management.html#thread.thread_management.thread.try_join_until" title="Member function try_join_until() EXTENSION"><code class="computeroutput"><span class="identifier">try_join_until</span></code></a></code> 48 </li> 49<li class="listitem"> 50 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable" title="Class condition_variable"><code class="computeroutput"><span class="identifier">condition_variable</span></code></a><span class="special">::</span><a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable.wait_for" title="template <class Rep, class Period> cv_status wait_for(boost::unique_lock<boost::mutex>& lock, const chrono::duration<Rep, Period>& rel_time)"><code class="computeroutput"><span class="identifier">wait_for</span></code></a></code> 51 </li> 52<li class="listitem"> 53 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable" title="Class condition_variable"><code class="computeroutput"><span class="identifier">condition_variable</span></code></a><span class="special">::</span><a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable.wait_until" title="template <class Clock, class Duration> cv_status wait_until(boost::unique_lock<boost::mutex>& lock, const chrono::time_point<Clock, Duration>& abs_time)"><code class="computeroutput"><span class="identifier">wait_until</span></code></a></code> 54 </li> 55<li class="listitem"> 56 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable_any" title="Class condition_variable_any"><code class="computeroutput"><span class="identifier">condition_variable_any</span></code></a><span class="special">::</span><a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable_any.wait_for" title="template <class lock_type, class Rep, class Period> cv_status wait_for(lock_type& lock, const chrono::duration<Rep, Period>& rel_time)"><code class="computeroutput"><span class="identifier">wait_for</span></code></a></code> 57 </li> 58<li class="listitem"> 59 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable_any" title="Class condition_variable_any"><code class="computeroutput"><span class="identifier">condition_variable_any</span></code></a><span class="special">::</span><a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable_any.wait_until" title="template <class lock_type, class Clock, class Duration> cv_status wait_until(lock_type& lock, const chrono::time_point<Clock, Duration>& abs_time)"><code class="computeroutput"><span class="identifier">wait_until</span></code></a></code> 60 </li> 61<li class="listitem"> 62 <code class="computeroutput"><a class="link" href="synchronization.html#thread.synchronization.mutex_concepts.timed_lockable" title="TimedLockable Concept"><code class="computeroutput"><span class="identifier">TimedLockable</span></code></a><span class="special">::</span><a class="link" href="synchronization.html#thread.synchronization.mutex_concepts.timed_lockable.try_lock_for" title="m.try_lock_for(rel_time)"><code class="computeroutput"><span class="identifier">try_lock_for</span></code></a></code> 63 </li> 64<li class="listitem"> 65 <code class="computeroutput"><a class="link" href="synchronization.html#thread.synchronization.mutex_concepts.timed_lockable" title="TimedLockable Concept"><code class="computeroutput"><span class="identifier">TimedLockable</span></code></a><span class="special">::</span><a class="link" href="synchronization.html#thread.synchronization.mutex_concepts.timed_lockable.try_lock_until" title="m.try_lock_until(abs_time)"><code class="computeroutput"><span class="identifier">try_lock_until</span></code></a></code> 66 </li> 67</ul></div> 68<div class="section"> 69<div class="titlepage"><div><div><h3 class="title"> 70<a name="thread.time.deprecated"></a><a class="link" href="time.html#thread.time.deprecated" title="Deprecated">Deprecated</a> 71</h3></div></div></div> 72<div class="toc"><dl class="toc"> 73<dt><span class="section"><a href="time.html#thread.time.deprecated.system_time">Typedef <code class="computeroutput"><span class="identifier">system_time</span></code></a></span></dt> 74<dt><span class="section"><a href="time.html#thread.time.deprecated.get_system_time">Non-member 75 function <code class="computeroutput"><span class="identifier">get_system_time</span><span class="special">()</span></code></a></span></dt> 76</dl></div> 77<p> 78 The time related functions introduced in Boost 1.35.0, using the <a class="link" href="../date_time.html" title="Chapter 13. Boost.Date_Time">Boost.Date_Time</a> 79 library are deprecated. These include (but are not limited to): 80 </p> 81<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 82<li class="listitem"> 83 <a class="link" href="thread_management.html#thread.thread_management.this_thread.sleep" title="Non-member function sleep() DEPRECATED"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">sleep</span><span class="special">()</span></code></a> 84 </li> 85<li class="listitem"> 86 <a class="link" href="thread_management.html#thread.thread_management.thread.timed_join" title="Member function timed_join() DEPRECATED"><code class="computeroutput"><span class="identifier">timed_join</span><span class="special">()</span></code></a> 87 </li> 88<li class="listitem"> 89 <a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable.timed_wait" title="bool timed_wait(boost::unique_lock<boost::mutex>& lock,boost::system_time const& abs_time)"><code class="computeroutput"><span class="identifier">timed_wait</span><span class="special">()</span></code></a> 90 </li> 91<li class="listitem"> 92 <a class="link" href="synchronization.html#thread.synchronization.mutex_concepts.timed_lockable.timed_lock" title="m.timed_lock(abs_time)"><code class="computeroutput"><span class="identifier">timed_lock</span><span class="special">()</span></code></a> 93 </li> 94</ul></div> 95<p> 96 For the overloads that accept an absolute time parameter, an object of type 97 <a class="link" href="time.html#thread.time.deprecated.system_time" title="Typedef system_time"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">system_time</span></code></a> 98 is required. Typically, this will be obtained by adding a duration to the 99 current time, obtained with a call to <a class="link" href="time.html#thread.time.deprecated.get_system_time" title="Non-member function get_system_time()"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">get_system_time</span><span class="special">()</span></code></a>. 100 e.g. 101 </p> 102<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">system_time</span> <span class="keyword">const</span> <span class="identifier">timeout</span><span class="special">=</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">get_system_time</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">milliseconds</span><span class="special">(</span><span class="number">500</span><span class="special">);</span> 103 104<span class="keyword">extern</span> <span class="keyword">bool</span> <span class="identifier">done</span><span class="special">;</span> 105<span class="keyword">extern</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">mutex</span> <span class="identifier">m</span><span class="special">;</span> 106<span class="keyword">extern</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">condition_variable</span> <span class="identifier">cond</span><span class="special">;</span> 107 108<span class="identifier">boost</span><span class="special">::</span><span class="identifier">unique_lock</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">mutex</span><span class="special">></span> <span class="identifier">lk</span><span class="special">(</span><span class="identifier">m</span><span class="special">);</span> 109<span class="keyword">while</span><span class="special">(!</span><span class="identifier">done</span><span class="special">)</span> 110<span class="special">{</span> 111 <span class="keyword">if</span><span class="special">(!</span><span class="identifier">cond</span><span class="special">.</span><span class="identifier">timed_wait</span><span class="special">(</span><span class="identifier">lk</span><span class="special">,</span><span class="identifier">timeout</span><span class="special">))</span> 112 <span class="special">{</span> 113 <span class="keyword">throw</span> <span class="string">"timed out"</span><span class="special">;</span> 114 <span class="special">}</span> 115<span class="special">}</span> 116</pre> 117<p> 118 For the overloads that accept a <span class="emphasis"><em>TimeDuration</em></span> parameter, 119 an object of any type that meets the <a class="link" href="../date_time/posix_time.html#date_time.posix_time.time_duration" title="Time Duration">Boost.Date_Time 120 Time Duration requirements</a> can be used, e.g. 121 </p> 122<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">sleep</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">milliseconds</span><span class="special">(</span><span class="number">25</span><span class="special">));</span> 123 124<span class="identifier">boost</span><span class="special">::</span><span class="identifier">mutex</span> <span class="identifier">m</span><span class="special">;</span> 125<span class="keyword">if</span><span class="special">(</span><span class="identifier">m</span><span class="special">.</span><span class="identifier">timed_lock</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">nanoseconds</span><span class="special">(</span><span class="number">100</span><span class="special">)))</span> 126<span class="special">{</span> 127 <span class="comment">// ...</span> 128<span class="special">}</span> 129</pre> 130<div class="section"> 131<div class="titlepage"><div><div><h4 class="title"> 132<a name="thread.time.deprecated.system_time"></a><a class="link" href="time.html#thread.time.deprecated.system_time" title="Typedef system_time">Typedef <code class="computeroutput"><span class="identifier">system_time</span></code></a> 133</h4></div></div></div> 134<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">thread</span><span class="special">/</span><span class="identifier">thread_time</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 135 136<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">system_time</span><span class="special">;</span> 137</pre> 138<p> 139 See the documentation for <a class="link" href="../date_time/posix_time.html#date_time.posix_time.ptime_class" title="Ptime"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">ptime</span></code></a> in the Boost.Date_Time library. 140 </p> 141</div> 142<div class="section"> 143<div class="titlepage"><div><div><h4 class="title"> 144<a name="thread.time.deprecated.get_system_time"></a><a class="link" href="time.html#thread.time.deprecated.get_system_time" title="Non-member function get_system_time()">Non-member 145 function <code class="computeroutput"><span class="identifier">get_system_time</span><span class="special">()</span></code></a> 146</h4></div></div></div> 147<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">thread</span><span class="special">/</span><span class="identifier">thread_time</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 148 149<span class="identifier">system_time</span> <span class="identifier">get_system_time</span><span class="special">();</span> 150</pre> 151<div class="variablelist"> 152<p class="title"><b></b></p> 153<dl class="variablelist"> 154<dt><span class="term">Returns:</span></dt> 155<dd><p> 156 The current time. 157 </p></dd> 158<dt><span class="term">Throws:</span></dt> 159<dd><p> 160 Nothing. 161 </p></dd> 162</dl> 163</div> 164</div> 165</div> 166</div> 167<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 168<td align="left"></td> 169<td align="right"><div class="copyright-footer">Copyright © 2007 -11 Anthony Williams<br>Copyright © 2011 -17 Vicente J. Botet Escriba<p> 170 Distributed under the Boost Software License, Version 1.0. (See accompanying 171 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 172 </p> 173</div></td> 174</tr></table> 175<hr> 176<div class="spirit-nav"> 177<a accesskey="p" href="parallel.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../thread.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="emulations.html"><img src="../../../doc/src/images/next.png" alt="Next"></a> 178</div> 179</body> 180</html> 181