summaryrefslogtreecommitdiff
path: root/doc/html/thread/time.html
blob: 2bc9973f0b7d338e0086235550343ff4673a2e88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Time Requirements</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../thread.html" title="Chapter&#160;33.&#160;Thread 4.7.0">
<link rel="prev" href="parallel.html" title="Parallel - Fork-Join -- EXPERIMENTAL">
<link rel="next" href="emulations.html" title="Emulations">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<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>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="thread.time"></a><a class="link" href="time.html" title="Time Requirements">Time Requirements</a>
</h2></div></div></div>
<div class="toc"><dl><dt><span class="section"><a href="time.html#thread.time.deprecated">Deprecated</a></span></dt></dl></div>
<p>
      As of Boost 1.50.0, the <span class="bold"><strong>Boost.Thread</strong></span> library
      uses Boost.Chrono library for all operations that require a time out as defined
      in the standard c++11. These include (but are not limited to):
    </p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
          <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>
        </li>
<li class="listitem">
          <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>
        </li>
<li class="listitem">
          <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>
        </li>
<li class="listitem">
          <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>
        </li>
<li class="listitem">
          <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 &lt;class Rep, class Period&gt; cv_status wait_for(boost::unique_lock&lt;boost::mutex&gt;&amp; lock, const chrono::duration&lt;Rep, Period&gt;&amp; rel_time)"><code class="computeroutput"><span class="identifier">wait_for</span></code></a></code>
        </li>
<li class="listitem">
          <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 &lt;class Clock, class Duration&gt; cv_status wait_until(boost::unique_lock&lt;boost::mutex&gt;&amp; lock, const chrono::time_point&lt;Clock, Duration&gt;&amp; abs_time)"><code class="computeroutput"><span class="identifier">wait_until</span></code></a></code>
        </li>
<li class="listitem">
          <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 &lt;class lock_type, class Rep, class Period&gt; cv_status wait_for(lock_type&amp; lock, const chrono::duration&lt;Rep, Period&gt;&amp; rel_time)"><code class="computeroutput"><span class="identifier">wait_for</span></code></a></code>
        </li>
<li class="listitem">
          <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 &lt;class lock_type, class Clock, class Duration&gt; cv_status wait_until(lock_type&amp; lock, const chrono::time_point&lt;Clock, Duration&gt;&amp; abs_time)"><code class="computeroutput"><span class="identifier">wait_until</span></code></a></code>
        </li>
<li class="listitem">
          <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>
        </li>
<li class="listitem">
          <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>
        </li>
</ul></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="thread.time.deprecated"></a><a class="link" href="time.html#thread.time.deprecated" title="Deprecated">Deprecated</a>
</h3></div></div></div>
<div class="toc"><dl>
<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>
<dt><span class="section"><a href="time.html#thread.time.deprecated.get_system_time">Non-member
        function <code class="computeroutput"><span class="identifier">get_system_time</span><span class="special">()</span></code></a></span></dt>
</dl></div>
<p>
        The time related functions introduced in Boost 1.35.0, using the <a class="link" href="../date_time.html" title="Chapter&#160;9.&#160;Boost.Date_Time">Boost.Date_Time</a>
        library are deprecated. These include (but are not limited to):
      </p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
            <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>
          </li>
<li class="listitem">
            <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>
          </li>
<li class="listitem">
            <a class="link" href="synchronization.html#thread.synchronization.condvar_ref.condition_variable.timed_wait" title="bool timed_wait(boost::unique_lock&lt;boost::mutex&gt;&amp; lock,boost::system_time const&amp; abs_time)"><code class="computeroutput"><span class="identifier">timed_wait</span><span class="special">()</span></code></a>
          </li>
<li class="listitem">
            <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>
          </li>
</ul></div>
<p>
        For the overloads that accept an absolute time parameter, an object of type
        <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>
        is required. Typically, this will be obtained by adding a duration to the
        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>.
        e.g.
      </p>
<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>

<span class="keyword">extern</span> <span class="keyword">bool</span> <span class="identifier">done</span><span class="special">;</span>
<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>
<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>

<span class="identifier">boost</span><span class="special">::</span><span class="identifier">unique_lock</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">mutex</span><span class="special">&gt;</span> <span class="identifier">lk</span><span class="special">(</span><span class="identifier">m</span><span class="special">);</span>
<span class="keyword">while</span><span class="special">(!</span><span class="identifier">done</span><span class="special">)</span>
<span class="special">{</span>
    <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>
    <span class="special">{</span>
        <span class="keyword">throw</span> <span class="string">"timed out"</span><span class="special">;</span>
    <span class="special">}</span>
<span class="special">}</span>
</pre>
<p>
        For the overloads that accept a <span class="emphasis"><em>TimeDuration</em></span> parameter,
        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
        Time Duration requirements</a> can be used, e.g.
      </p>
<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>

<span class="identifier">boost</span><span class="special">::</span><span class="identifier">mutex</span> <span class="identifier">m</span><span class="special">;</span>
<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>
<span class="special">{</span>
    <span class="comment">//  ...</span>
<span class="special">}</span>
</pre>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<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>
</h4></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</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">&gt;</span>

<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>
</pre>
<p>
          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.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<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
        function <code class="computeroutput"><span class="identifier">get_system_time</span><span class="special">()</span></code></a>
</h4></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</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">&gt;</span>

<span class="identifier">system_time</span> <span class="identifier">get_system_time</span><span class="special">();</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl>
<dt><span class="term">Returns:</span></dt>
<dd><p>
                The current time.
              </p></dd>
<dt><span class="term">Throws:</span></dt>
<dd><p>
                Nothing.
              </p></dd>
</dl>
</div>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2007 -11 Anthony Williams<br>Copyright &#169; 2011 -15 Vicente J. Botet Escriba<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        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>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<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>
</div>
</body>
</html>