<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 951: Various threading bugs #1</title>
<meta property="og:title" content="Issue 951: Various threading bugs #1">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue951.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#C++11">C++11</a> status.</em></p>
<h3 id="951"><a href="lwg-defects.html#951">951</a>. Various threading bugs #1</h3>
<p><b>Section:</b> 30.4.1 <a href="https://wg21.link/time.traits.is.fp">[time.traits.is.fp]</a> <b>Status:</b> <a href="lwg-active.html#C++11">C++11</a>
 <b>Submitter:</b> Pete Becker <b>Opened:</b> 2009-01-07 <b>Last modified:</b> 2021-06-06</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++11">C++11</a> status.</p>
<p><b>Discussion:</b></p>

<p>
Related to <a href="lwg-defects.html#953" title="Various threading bugs #3 (Status: Resolved)">953</a><sup><a href="https://cplusplus.github.io/LWG/issue953" title="Latest snapshot">(i)</a></sup>.
</p>

<p>
 [time.traits.is_fp] says that the type <code>Rep</code> "is
assumed to be ... a class emulating an integral type." What are the
requirements for such a type?
</p>
<p><i>[
2009-05-10 Howard adds:
]</i></p>


<blockquote><p>
<code>IntegralLike</code>.
</p></blockquote>

<p><i>[
Batavia (2009-05):
]</i></p>

<blockquote>
<p>
As with issue <a href="lwg-defects.html#953" title="Various threading bugs #3 (Status: Resolved)">953</a><sup><a href="https://cplusplus.github.io/LWG/issue953" title="Latest snapshot">(i)</a></sup>,
we recommend this issue be addressed in the context of providing concepts for the entire <code>thread</code> header.
</p>
<p>
We look forward to proposed wording.
</p>
<p>
Move to Open.
</p>
</blockquote>

<p><i>[
2009-08-01 Howard adds:
]</i></p>


<blockquote>
<p>
I have surveyed all clauses of  [time.traits.duration_values],
30.4.3 <a href="https://wg21.link/time.traits.specializations">[time.traits.specializations]</a> and 30.5 <a href="https://wg21.link/time.duration">[time.duration]</a>.
I can not find any clause which involves the use of a <code>duration::rep</code> type
where the requirements on the <code>rep</code> type are not clearly spelled out.
These requirements were carefully crafted to allow any arithmetic type, or
any user-defined type emulating an arithmetic type.
</p>

<p>
Indeed, <code>treat_as_floating_point</code>
becomes completely superfluous if <code>duration::rep</code> can never be a class type.
</p>

<p>
There will be some <code>Rep</code> types which will not meet the requirements of
<em>every</em> <code>duration</code> operation.  This is no different than the fact
that <code>vector&lt;T&gt;</code> can easily be used for types <code>T</code> which are
not <code>DefaultConstructible</code>, even though some members of <code>vector&lt;T&gt;</code>
require <code>T</code> to be <code>DefaultConstructible</code>.  This is why the requirements
on <code>Rep</code> are specified for each operation individually.
</p>

<p>
In  [time.traits.is_fp] p1:
</p>

<blockquote><pre>
template &lt;class Rep&gt; struct treat_as_floating_point
  : is_floating_point&lt;Rep&gt; { };
</pre>

<blockquote><p>
The <code>duration</code> template uses the <code>treat_as_floating_point</code> trait to help
determine if a <code>duration</code> object can be converted to another <code>duration</code>
with a different tick period. If <code>treat_as_floating_point&lt;Rep&gt;::value</code> is
<code>true</code>, then <code>Rep</code> is a floating-point type and implicit conversions are
allowed among <code>duration</code>s. Otherwise, the implicit convertibility depends
on the tick periods of the <code>duration</code>s. If <code>Rep</code> is
<span style="text-decoration:underline">a class type which emulates a floating-point type</span>,
the author of <code>Rep</code> can specialize <code>treat_as_floating_point</code> so that
<code>duration</code> will treat this <code>Rep</code> as if it were a floating-point type.
Otherwise <code>Rep</code> is assumed to be an integral type or
<span style="text-decoration:underline">a class emulating an integral type</span>.
</p></blockquote>
</blockquote>

<p>
The phrases "a class type which emulates a floating-point type" and
"a class emulating an integral type" are clarifying phrases which refer to
the summation of all the requirements on the <code>Rep</code> type specified in
detail elsewhere (and <em>should not</em> be repeated here).
</p>

<p>
This specification has been implemented, now multiple times, and the experience
has been favorable.  The current specification clearly specifies the requirements
at each point of use (though I'd be happy to fix any place I may have missed,
but none has been pointed out).
</p>

<p>
I am amenable to improved wording of this paragraph (and any others), but do not have any
suggestions for improved wording at this time.  I am <em>strongly</em> opposed to
changes which would significantly alter the semantics of the
specification under 30 <a href="https://wg21.link/time">[time]</a> without firmly grounded and
documented rationale, example implementation, testing, and user
experience which relates a positive experience.
</p>

<p>
I recommend NAD unless someone wants to produce some clarifying wording.
</p>
</blockquote>

<p><i>[
2009-10 Santa Cruz:
]</i></p>


<blockquote><p>
Stefanus to provide wording to turn this into a note.
</p></blockquote>

<p><i>[
2010-02-11 Stefanus provided wording.
]</i></p>



<p><i>[
2010 Rapperswil:
]</i></p>


<blockquote><p>
Move to Ready.
</p></blockquote>

<p><i>[
Adopted at 2010-11 Batavia
]</i></p>




<p id="res-951"><b>Proposed resolution:</b></p>
<p>
Change  [time.traits.is_fp]/1:
</p>

<blockquote><p>
1 The <code>duration</code> template uses the <code>treat_as_floating_point</code> trait
to help determine if a <code>duration</code> object can be converted to another
<code>duration</code> with a different tick period. If
<code>treat_as_floating_point&lt;Rep&gt;::value</code> is <code>true</code>, then
<del><code>Rep</code> is a floating-point type and</del> implicit conversions are allowed among
<code>duration</code>s. Otherwise, the implicit convertibility depends on the tick
periods of the <code>duration</code>s. <del>If <code>Rep</code> is a class type which
emulates a floating-point type, the author of <code>Rep</code> can specialize
<code>treat_as_floating_point</code> so that duration will treat this <code>Rep</code>
as if it were a floating-point type. Otherwise <code>Rep</code> is assumed to be an
integral type or a class emulating an integral type.</del>
<ins>[<i>Note:</i> The intention of this trait is to indicate whether a given
class behaves like a floating point type, and thus allows division of one value
by another with acceptable loss of precision. If
<code>treat_as_floating_point&lt;Rep&gt;::value</code> is <code>false</code>,
<code>Rep</code> will be treated as if it behaved like an integral type for the
purpose of these conversions. &mdash; <i>end note</i>]</ins>
</p></blockquote>






</body>
</html>
