<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<title>N2552=08-0062, Using ytime for Times in the Thread Support Library</title>
	<meta name="generator" content="BBEdit 8.6" />
<style type="text/css" title="text/css">
/* <![CDATA[ */
* { font-family: serif; }
*.code { font-size: 120%; font-family: monospace; font-weight: bolder; }
*.non-code { font-style: italic; font-family: monospace; }
p > span.non-code { font-size: 120%; }
*.link-target { font-weight: bolder; }
*.copyright { font-style: italic; }
h1 { text-align: center; }
div.group { border-bottom: double; padding-bottom: .5em; }
div.subgroup { border-bottom: thin solid; padding-bottom: .5em; }
div.added { color: green; text-decoration: underline; }
div.removed { color: red; text-decoration: line-through; }
div.block { border-bottom: thin solid; border-top: thin solid; }
div.menu { padding-top: .5em; padding-bottom: .5em; }
div.menu a { padding-right: .3em; }
div.menu a + a { padding-left: .45em; border-left: thin solid; line-height: 1.3em; }
table.heading { border-collapse: separate; float: right; padding-right: 1em; }
td.descr { padding: 0; text-align: right; font-style: italic; font-weight: bold; }
td.descr:after { content: ":"; }
td.emptydescr { padding: 0; }
td.value { padding: 0; padding-left: 1ex; }
pre { font-family: monospace; }
pre a.code { font-size: 100%; }
pre .decl { font-weight: bolder; font-size: 80%; }
span.reqmt { font-style: italic; }
span.reqmt:after { content: ":" }
span.title { font-style: italic; }
span.added { color: green; text-decoration: underline; }
span.addedd { color: blue; text-decoration: underline; }
span.math { font-style: italic; }
span.removed { color: red; text-decoration: line-through; }
/* ]]> */
</style>
</head>
<body>

<div class="group">
<h1>Using <span class="code">ytime</span> for Times in the Thread Support Library</h1>

<table class="heading">
<tr>
  <td class="descr">Document number</td><td class="value">N2552=08-0062</td>
</tr>
<tr>
  <td class="descr">Date</td><td class="value">2008-02-28</td>
</tr>
<tr>
  <td class="descr">Project</td><td class="value">Programming Language C++</td>
</tr>
<tr>
  <td class="descr">Reference</td><td class="value">ISO/IEC IS 14882:2003(E)</td>
</tr>
<tr>
  <td class="descr">Reply to</td><td class="value">Pete Becker</td>
</tr>
<tr>
  <td class="emptydescr"></td><td class="value">Roundhouse Consulting, Ltd.</td>
</tr>
<tr>
  <td class="emptydescr"></td><td class="value">pete@versatilecoding.com</td>
</tr>
</table>
<p style="clear:both"></p>
</div>

<p>These are the changes to N2521, <span class="title">Working Draft, Standard for Programming Language
C++</span>, to replace the date and time material in Clause 31 with <span class="code">ytime</span>.</p>

<p>Additions to the previous version of this draft paper are <span class="addedd">marked like this</span>.
Additions and changes include:</p>

<ul>
<li>added words to more clearly describe how the members <span class="code">sec</span> and
<span class="code">nsec</span> interact to define a time</li>
<li>added changes to the Effects clauses of various <span class="code">timed_wait</span> and
<span class="code">timed_wait_until</span> member functions to correctly specify
their behavior using the new names</li>
<li>changed <span class="code">xtime</span> to <span class="code">ytime</span> throughout (not marked).</li>
</ul>

<p>Changes to the working draft:</p>

<ol>
<li>In 30.1.4, [thread.req.timing], replace paragraphs 1 and 2 with the following:
<p><span class="added">The class <span class="code">ytime</span> designates a
	time duration or a
	point in time. The headers <span class="code">&lt;thread&gt;</span> and
	<span class="code">&lt;condition&gt;</span> shall provide idempotent definitions
	of this class and of the enumeration <span class="code">TIME_UTC</span>.
</p></li>

<li>In 30.2, [thread.threads], change the synopsis for the header
<span class="code">&lt;thread&gt;</span> to read as follows:
<pre><span class="added">// times [cross-reference goes here]</span>
<span class="added">class ytime;</span>
<span class="added">enum { TIME_UTC = <span class="non-code">&lt;integer constant expression&gt;</span> };</span>
<span class="added">int ytime_get(ytime&amp; xt, int time_base);</span>
void <span class="removed">sleep</span> <span class="added">sleep_until</span> (const <span class="removed">system_time</span> <span class="added">ytime</span>&amp; abs_time);
<span class="removed">template &lt;class Duration&gt;</span>
    void sleep(const <span class="removed">Duration</span> <span class="added">ytime</span>&amp; rel_time</span>);</pre></li>

<li><p>Before 30.2.1, [thread.thread.class], add a new subclause,
<span class="title">Times</span>, to read as follows:</p>
	
<pre><span class="added">enum { TIME_UTC = <span class="non-code">&lt;integer constant expression&gt;</span> };</span></pre>

<p><span class="added">The compile-time constant is a non-zero value that designates
	the system&rsquo;s approximation of Coordinated Universal
Time (UTC) as the time base for the values set by <span class="code">ytime_get</span>.</span></p>

<pre><span class="added">struct ytime {</span>
    <span class="added">time_t sec;</span>
    <span class="added">unsigned long nsec;</span>
    <span class="added">};</span></pre>

<p><span class="added">The struct <span class="code">ytime</span> contains members that describe times with
nanosecond resolution. An object of type <span class="code">ytime</span> can represent a
time duration or it can represent an absolute time. The member <span class="code">sec</span>
holds the number of seconds and the member <span class="code">nsec</span> holds the
number of nanoseconds.</span> <span class="addedd">The time represented by such an object is
<span class="math">sec * 1,000,000,000 + nsec</span> nanoseconds past the
implementation-specific epoch.</span></p>

<p><span class="added">The type <span class="code">time_t</span> is defined in
<span class="code">&lt;ctime&gt;</span>.</span></p>

<pre><span class="added">int ytime_get(ytime&amp; xt, int time_base);</span></pre>

<p><span class="added">The function sets the
<span class="code">ytime</span>
object referred to by <span class="code">xt</span> to hold
the current time
based on the non-zero time base selector <span class="code">time_base</span>.
If successful it
returns <span class="code">time_base</span>;
otherwise it returns 0. [Note: The value of <span class="code">time_base</span>
will typically be <span class="code">TIME_UTC.</span> -- end note]</span></p></li>

<li>In 30.2.2, [thread.thread.this], change the synopsis for
	<span class="code">namespace this_thread</span> to read as follows:

<pre>void <span class="removed">sleep</span> <span class="added">sleep_until</span> (const <span class="removed">system_time</span> <span class="added">ytime</span>&amp; abs_time);
<span class="removed">template &lt;class Duration&gt;</span>
void sleep(const <span class="removed">Duration</span> <span class="added">ytime</span>&amp; rel_time</span>);</pre></li>

<li><p>In 30.2.2, [thread.thread.this], change the declaration of the first overload of the <span class="code">sleep</span> function to read as follows:</p>

<pre>void this_thread::<span class="removed">sleep</span> <span class="added">sleep_until</span> (const <span class="removed">system_time</span> <span class="added">ytime</span>&amp; abs_time);</pre></li>

<li><p>In 30.2.2, [thread.thread.this], change the declaration of the second overload of the <span class="code">sleep</span> function to read as follows:</p>

<pre><span class="removed">template &lt;class Duration&gt;</span>
void this_thread::sleep(const <span class="removed">Duration</span> <span class="added">ytime</span>&amp; rel_time);</pre></li>

<li>In 30.4, [thread.condition], add the following to the synopsis for the header
	<span class="code">&lt;condition_variable&gt;</span>
<pre><span class="added">// times [cross-reference goes here]</span>
<span class="added">class ytime;</span>
<span class="added">enum { TIME_UTC = &lt;integer constant expression&gt; };</span>
<span class="added">int ytime_get(ytime&amp; xt, int time_base);</span>
</pre></li>

<li>In 30.4.1, [thread.condition.condvar], change the synopsis for the class
	<span class="code">condition_variable</span> to read as follows:
<pre><span class="removed">template &lt;class Duration&gt;</span>
bool timed_wait(unique_lock&lt;mutex&gt;&amp; lock, const <span class="removed">Duration</span> <span class="added">ytime</span> &amp; rel_time);
bool <span class="removed">timed_wait</span> <span class="added">timed_wait_until</span> (unique_lock&lt;mutex&gt;&amp; lock,
    const <span class="removed">system_time</span> <span class="added">ytime</span>&amp; abs_time);
template &lt;class Predicate&gt;
    bool <span class="removed">timed_wait</span> <span class="added">timed_wait_until</span> (unique_lock&lt;mutex&gt;&amp; lock,
        const <span class="removed">system_time</span> <span class="added">ytime</span>&amp; abs_time, Predicate pred);
template &lt;<span class="removed">class Duration,</span> class Predicate&gt;
    bool timed_wait(unique_lock&lt;mutex&gt;&amp; lock, const <span class="removed">Duration</span> <span class="added">ytime</span> &amp; rel_time,
        Predicate pred);
</pre></li>

<li><p>In 30.4.1, [thread.condition.condvar], change the declaration of the first overload of the
	<span class="code">timed_wait</span> function to read as follows:</p>
<pre>bool <span class="removed">timed_wait</span> <span class="added">timed_wait_until</span> (unique_lock&lt;mutex&gt;&amp; lock, const <span class="removed">system_time</span> <span class="added">ytime</span>&amp; abs_time);</pre>
</li>

<li><p>In 30.4.1, [thread.condition.condvar], change the declaration of the second overload of the
	<span class="code">timed_wait</span> function to read as follows:</p>
<pre><span class="removed">template &lt;class Duration&gt;</span>
bool timed_wait(unique_lock&lt;mutex&gt;&amp; lock, const <span class="removed">Duration</span> <span class="added">ytime</span>&amp; rel_time);</pre>
</li>

<li><p><span class="addedd">In 30.4.1, [thread.condition.condvar], change the Effects clause of the second overload of the
	<span class="code">timed_wait</span> function to read as follows:</span></p>
<span class="addedd"><pre>ytime xt;
ytime_get(xt, TIME_UTC);
xt.sec += rel_time.sec;
xt.nsec += rel_time.nsec;
timed_wait_until(lock, xt);</pre></span></li>

<li><p>In 30.4.1, [thread.condition.condvar], change the declaration of the third overload of the
	<span class="code">timed_wait</span> function to read as follows:</p>
<pre>template &lt;class Predicate&gt;
    bool <span class="removed">timed_wait</span> <span class="added">timed_wait_until</span> (unique_lock&lt;mutex&gt;&amp; lock,
        const <span class="removed">system_time</span> <span class="added">ytime</span>&amp; abs_time, Predicate pred);</pre>
</li>

<li><p><span class="addedd">In 30.4.1, [thread.condition.condvar], change the Effects clause of the third overload of the
	<span class="code">timed_wait</span> function to read as follows:</span></p>
<pre>while (!pred())
  if (!<span class="removed">timed_wait</span> <span class="addedd">timed_wait_until</span>(lock, abs_time))
    return pred();
return true;</pre></li>

<li><p>In 30.4.1, [thread.condition.condvar], change the declaration of the fourth overload of the
	<span class="code">timed_wait</span> function to read as follows:</p>
<pre>template &lt;<span class="removed">class Duration,</span> class Predicate&gt;
    bool timed_wait(unique_lock&lt;mutex&gt;&amp; lock,
        const <span class="removed">Duration</span> <span class="added">ytime</span>&amp; rel_time, Predicate pred);</pre>
</li>

<li><p><span class="addedd">In 30.4.1, [thread.condition.condvar], change the Effects clause of the fourth overload of the
	<span class="code">timed_wait</span> function to read as follows:</span></p>
<span class="addedd"><pre>ytime xt;
ytime_get(xt, TIME_UTC);
xt.sec += rel_time.sec;
xt.nsec += rel_time.nsec;
timed_wait_until(lock, xt, std::move(pred));</pre></span></li>


<li><p>In 30.4.2, [thread.condition.condvarany], change the synopsis for the class
	<span class="code">condition_variable_any</span> to read as follows:
<pre>template &lt;class Lock&gt;
    bool <span class="removed">timed_wait</span> <span class="added">timed_wait_until</span> (Lock&amp; lock, const <span class="removed">system_time</span> <span class="added">ytime</span>&amp; abs_time);
template &lt;class Lock<span class="removed">, class Duration</span>&gt;
    bool timed_wait(Lock&amp; lock, const <span class="removed">Duration</span> <span class="added">ytime</span> &amp; rel_time);
template &lt;class Lock, class Predicate&gt;
    bool <span class="removed">timed_wait</span> <span class="added">timed_wait_until</span> (Lock&amp; lock, const <span class="removed">system_time</span> <span class="added">ytime</span>&amp; abs_time, Predicate pred);
template &lt;class Lock, <span class="removed">class Duration,</span> class Predicate&gt;
    bool timed_wait(Lock&amp; lock, const <span class="removed">Duration</span> <span class="added">ytime</span> &amp; rel_time, Predicate pred);
</pre>

<li><p>In 30.4.2, [thread.condition.condvarany], change the declaration of the first overload of the
	<span class="code">timed_wait</span> function to read as follows:</p>
<pre>template &lt;class Lock&gt;
    bool <span class="removed">timed_wait</span> <span class="added">timed_wait_until</span> (Lock lock, const <span class="removed">system_time</span> <span class="added">ytime</span>&amp; abs_time);</pre>
</li>

<li><p>In 30.4.2, [thread.condition.condvarany], change the declaration of the second overload of the
	<span class="code">timed_wait</span> function to read as follows:</p>
<pre>template &lt;class Lock<span class="removed">, class Duration</span>&gt;
    bool timed_wait(Lock lock, const <span class="removed">Duration</span> <span class="added">ytime</span>&amp; rel_time);</pre>
</li>

<li><p><span class="addedd">In 30.4.2, [thread.condition.condvarany], change the Effects clause of the second overload of the
	<span class="code">timed_wait</span> function to read as follows:</span></p>
<span class="addedd"><pre>ytime xt;
ytime_get(xt, TIME_UTC);
xt.sec += rel_time.sec;
xt.nsec += rel_time.nsec;
timed_wait_until(lock, xt);</pre></span></li>


<li><p>In 30.4.2, [thread.condition.condvarany], change the declaration of the third overload of the
	<span class="code">timed_wait</span> function to read as follows:</p>
<pre>template &lt;class Lock, class Predicate&gt;
    bool <span class="removed">timed_wait</span> <span class="added">timed_wait_until</span> (Lock lock,
        const <span class="removed">system_time</span> <span class="added">ytime</span>&amp; abs_time, Predicate pred);</pre>
</li>

<li><p><span class="addedd">In 30.4.2, [thread.condition.condvarany], change the Effects clause of the third overload of the
	<span class="code">timed_wait</span> function to read as follows:</span></p>
<pre>while (!pred())
  if (!<span class="removed">timed_wait</span> <span class="addedd">timed_wait_until</span>(lock, abs_time))
    return pred();
return true;</pre></li>

<li><p>In 30.4.2, [thread.condition.condvarany], change the declaration of the fourth overload of the
	<span class="code">timed_wait</span> function to read as follows:</p>
<pre>template &lt;class Lock, <span class="removed">class Duration,</span> class Predicate&gt;
    bool timed_wait(Lock lock,
        const <span class="removed">Duration</span> <span class="added">ytime</span>&amp; rel_time, Predicate pred);</pre>
</li>

<li><p><span class="addedd">In 30.4.2, [thread.condition.condvarany], change the Effects clause of the fourth overload of the
	<span class="code">timed_wait</span> function to read as follows:</span></p>
<span class="addedd"><pre>ytime xt;
ytime_get(xt, TIME_UTC);
xt.sec += rel_time.sec;
xt.nsec += rel_time.nsec;
timed_wait_until(lock, xt, std::move(pred));</pre></span></li>


<li><p>Remove clause 31.</p></li>

</ol>

</body>
</html>
