|
Boost-Commit : |
From: hinnant_at_[hidden]
Date: 2007-11-30 18:05:10
Author: hinnant
Date: 2007-11-30 18:05:09 EST (Fri, 30 Nov 2007)
New Revision: 41518
URL: http://svn.boost.org/trac/boost/changeset/41518
Log:
Added cv::timed_wait overloads
Text files modified:
sandbox/committee/LWG/thread_library.html | 72 +++++++++++++++++++++++----------------
1 files changed, 43 insertions(+), 29 deletions(-)
Modified: sandbox/committee/LWG/thread_library.html
==============================================================================
--- sandbox/committee/LWG/thread_library.html (original)
+++ sandbox/committee/LWG/thread_library.html 2007-11-30 18:05:09 EST (Fri, 30 Nov 2007)
@@ -2685,6 +2685,8 @@
void wait(unique_lock<mutex>& <var>lock</var>);
template <class Predicate>
void wait(unique_lock<mutex>& <var>lock</var>, Predicate <var>pred</var>);
+ template <class Duration>
+ bool timed_wait(unique_lock<mutex>& <var>lock</var>, const Duration& <var>rel_time</var>);
bool timed_wait(unique_lock<mutex>& <var>lock</var>, const system_time& <var>abs_time</var>);
template <class Predicate>
bool timed_wait(unique_lock<mutex>& <var>lock</var>, const system_time& <var>abs_time</var>, Predicate <var>pred</var>);
@@ -2928,40 +2930,28 @@
</dd>
</dl>
-<p>
-[<i>Note:</i>
-For condition variables,
-time duration overloads are not provided
-for the <code>timed_wait</code> members
-that do not take a <code>Predicate</code>.
-Spurious wakeups would cause endless loops
-unless extraordinary care were taken.
-The composability of absolute time provides an equivalent,
-but terminating, idiom:
-</p>
+</blockquote>
-<blockquote>
<pre><code>
-mutex mut;
-condition_variable cv;
-...
-system_time abs_time = get_system_time() + seconds(1);
-bool within_time = true;
-while (within_time && !pred())
- within_time = cv.timed_wait(mut, abs_time);
-if (pred()) ...
+template <class Duration>
+ bool timed_wait(unique_lock<mutex>& <var>lock</var>, const Duration& <var>rel_time</var>);
</code></pre>
-</blockquote>
-<p>
-Notice that changing the <code>time_wait</code> call
-to <code>cv.timed_wait(mut, get_system_time() + seconds(1))</code>
-to eliminate the <code>abs_time</code> variable could result in an endless loop.
-</p>
+<blockquote>
+<dl>
+<dt>Effects:</dt>
+<dd>
+As if returns <code>timed_wait(<var>lock</var>, get_current_time() + <var>rel_time</var>)</code>.
+</dd>
-<p>
-<i>--end note</i>]
-</p>
+<dt>Returns:</dt>
+<dd>
+<code>true</code> if the call to <code>timed_wait</code> is notified
+prior to the indicated timeout,
+otherwise returns <code>false</code>.
+</dd>
+
+</dl>
</blockquote>
<pre><code>
@@ -3090,6 +3080,8 @@
void wait(Lock& <var>lock</var>, Predicate <var>pred</var>);
template <class Lock>
bool timed_wait(Lock& <var>lock</var>, const system_time& <var>abs_time</var>);
+ template <class Lock, class Duration>
+ bool timed_wait(Lock& <var>lock</var>, const Duration& <var>rel_time</var>);
template <class Lock, class Predicate>
bool timed_wait(Lock& <var>lock</var>, const system_time& <var>abs_time</var>, Predicate <var>pred</var>);
template <class Lock, class Duration, class Predicate>
@@ -3297,6 +3289,28 @@
</blockquote>
<pre><code>
+template <class Lock, class Duration>
+ bool timed_wait(Lock& <var>lock</var>, const Duration& <var>rel_time</var>);
+</code></pre>
+
+<blockquote>
+<dl>
+<dt>Effects:</dt>
+<dd>
+As if returns <code>timed_wait(<var>lock</var>, get_current_time() + <var>rel_time</var>)</code>.
+</dd>
+
+<dt>Returns:</dt>
+<dd>
+<code>true</code> if the call to <code>timed_wait</code> is notified
+prior to the indicated timeout,
+otherwise returns <code>false</code>.
+</dd>
+
+</dl>
+</blockquote>
+
+<pre><code>
template <class Lock, class Predicate>
bool timed_wait(Lock& <var>lock</var>, const system_time& <var>abs_time</var>, Predicate <var>pred</var>);
</code></pre>
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk