<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 889: thread::id comparisons</title>
<meta property="og:title" content="Issue 889: thread::id comparisons">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue889.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#Resolved">Resolved</a> status.</em></p>
<h3 id="889"><a href="lwg-defects.html#889">889</a>. <code>thread::id</code> comparisons</h3>
<p><b>Section:</b> 32.4.3.2 <a href="https://wg21.link/thread.thread.id">[thread.thread.id]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Lawrence Crowl <b>Opened:</b> 2008-09-15 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#thread.thread.id">issues</a> in [thread.thread.id].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>

<p><b>Addresses UK 324</b></p>

<p>
The <code>thread::id</code> type supports the full set of comparison operators.  This
is substantially more than is required for the associative containers that
justified them.  Please place an issue against the threads library.
</p>

<p><i>[
San Francisco:
]</i></p>


<blockquote>
<p>
Would depend on proposed extension to POSIX, or non-standard extension.
What about hash? POSIX discussing op. POSIX not known to be considering
support needed for hash, op.
</p>
<p>
Group expresses support for putting ids in both unordered and ordered containers.
</p>
</blockquote>

<p><i>[
post San Francisco:
]</i></p>


<blockquote>
<p>
Howard:  It turns out the current working paper
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2723.pdf">N2723</a>
<i>already has</i> <code>hash&lt;thread::id&gt;</code>
(22.10 <a href="https://wg21.link/function.objects">[function.objects]</a>, 22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>).  We simply
overlooked it in the meeting.  It is a good thing we voted in favor of it
(again). :-)
</p>
<p>
Recommend NAD.
</p>

</blockquote>

<p><i>[
Post Summit:
]</i></p>


<blockquote><p>
Recommend to close as NAD. For POSIX, see if we need to add a function to
convert <code>pthread_t</code> to integer.
</p></blockquote>

<p><i>[
Post Summit, Alisdair adds:
]</i></p>


<blockquote>
<p>
The recommendation for LWG-889/UK-324 is NAD, already specified.
</p>
<p>
It is not clear to me that the specification is complete.
</p>
<p>
In particular, the synopsis of <code>&lt;functional&gt;</code> in 
22.10 <a href="https://wg21.link/function.objects">[function.objects]</a> does not mention <code>hash&lt; thread::id&gt;</code> 
nor <code>hash&lt; error_code &gt;</code>, although their existence is 
implied by 22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>, p1.
</p>
<p>
I am fairly uncomfortable putting the declaration for the
<code>thread_id</code> specialization into <code>&lt;functional&gt;</code> as
<code>id</code> is a nested class inside <code>std::thread</code>, so it implies
that <code>&lt;functional&gt;</code> would require the definition of the
<code>thread</code> class template in order to forward declared
<code>thread::id</code> and form this specialization.
</p>
<p>
It seems better to me that the dependency goes the other way around
(<code>&lt;thread&gt;</code> will more typically make use of
<code>&lt;functional&gt;</code> than vice-versa) and the
<code>hash&lt;thread::id&gt;</code> specialization be declared in the
<code>&lt;thread&gt;</code> header.
</p>
<p>
I think <code>hash&lt;error_code&gt;</code> could go into either
<code>&lt;system_error&gt;</code> or <code>&lt;functional&gt;</code> and have no
immediate preference either way.  However, it should clearly appear in
the synopsis of one of these two.
</p>
<p>
Recommend moving 889 back to open, and tying in a reference to UK-324.
</p>
</blockquote>

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

<blockquote><p>
Howard observes that <code>thread::id</code> need not be a nested class;
it could be a <code>typedef</code> for a more visible type.
</p></blockquote>

<p><i>[
2009-05-24 Alisdair adds:
]</i></p>

<blockquote><p>
I do not believe this is correct.  <code>thread::id</code> is explicitly documents as a
nested class, rather than as an unspecified typedef analogous to an
iterator.  If the intent is that this is not implemented as a nested class
(under the as-if freedoms) then this is a novel form of standardese.
</p></blockquote>

<p><i>[
2009-07 Frankfurt
]</i></p>


<blockquote><p>
Decided we want to move hash specialization for thread_id to the thread
header. Alisdair to provide wording.
</p></blockquote>

<p><i>[
2009-07-28 Alisdair provided wording, moved to Review.
]</i></p>


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


<blockquote><p>
Add a strike for <code>hash&lt;thread::id&gt;</code>. Move to Ready
</p></blockquote>

<p><i>[
2009-11-13 The proposed wording of <a href="lwg-defects.html#1182" title="Unfortunate hash dependencies (Status: C++11)">1182</a><sup><a href="https://cplusplus.github.io/LWG/issue1182" title="Latest snapshot">(i)</a></sup> is a superset of the
wording in this issue.
]</i></p>


<p><i>[
2010-02-09 Moved from Ready to Open:
]</i></p>


<blockquote>
<p>
Issue <a href="lwg-defects.html#1182" title="Unfortunate hash dependencies (Status: C++11)">1182</a><sup><a href="https://cplusplus.github.io/LWG/issue1182" title="Latest snapshot">(i)</a></sup> is not quite a superset of this issue and it is controversial
whether or not the note:
</p>

<blockquote><p>
hash template specialization allows <code>thread::id</code> objects to be used as keys in
unordered containers.
</p></blockquote>

<p>
should be added to the WP.
</p>


</blockquote>

<p><i>[
2010-02-09 Objections to moving this to <del>NAD Editorial</del><ins>Resolved</ins>, addressed by <a href="lwg-defects.html#1182" title="Unfortunate hash dependencies (Status: C++11)">1182</a><sup><a href="https://cplusplus.github.io/LWG/issue1182" title="Latest snapshot">(i)</a></sup> have been removed.  Set to Tentatively <del>NAD Editorial</del><ins>Resolved</ins>.
]</i></p>




<p><b>Rationale:</b></p>
<p>
Solved by <a href="lwg-defects.html#1182" title="Unfortunate hash dependencies (Status: C++11)">1182</a><sup><a href="https://cplusplus.github.io/LWG/issue1182" title="Latest snapshot">(i)</a></sup>.
</p>


<p id="res-889"><b>Proposed resolution:</b></p>

<p>
Remove the following prototype from the synopsis in
22.10 <a href="https://wg21.link/function.objects">[function.objects]</a>:
</p>

<blockquote><pre><del>
template &lt;&gt; struct hash&lt;std::thread::id&gt;;
</del></pre></blockquote>

<p>
Add to 32.4 <a href="https://wg21.link/thread.threads">[thread.threads]</a>, p1 Header <code>&lt;thread&gt;</code> synopsis:
</p>

<blockquote><pre>
<ins>template &lt;class T&gt; struct hash;
template &lt;&gt; struct hash&lt;thread::id&gt;;</ins>
</pre></blockquote>

<p>
Add template specialization below class definition in 32.4.3.2 <a href="https://wg21.link/thread.thread.id">[thread.thread.id]</a>
</p>

<blockquote><pre>
<ins>template &lt;&gt;
struct hash&lt;thread::id&gt; : public unary_function&lt;thread::id, size_t&gt; {
   size_t operator()(thread::id val) const;
};</ins>
</pre></blockquote>

<p>
Extend note in p2 32.4.3.2 <a href="https://wg21.link/thread.thread.id">[thread.thread.id]</a> with second sentence:
</p>

<blockquote><p>
[<i>Note:</i> Relational operators allow <code>thread::id</code> objects to be used
as keys in associative containers.
<ins><code>hash</code> template specialization allows <code>thread::id</code> objects to be used as keys
in unordered containers.</ins>
&mdash; <i>end note</i>]
</p></blockquote>

<p>
Add new paragraph to end of 32.4.3.2 <a href="https://wg21.link/thread.thread.id">[thread.thread.id]</a>
</p>

<blockquote><pre>
<ins>template &lt;&gt; struct hash&lt;thread::id&gt;;</ins>
</pre>
<blockquote><p><ins>
An explicit specialization of the class template hash (22.10.19 <a href="https://wg21.link/unord.hash">[unord.hash]</a>)
shall be provided for the type <code>thread::id</code>.
</ins></p></blockquote>
</blockquote>





</body>
</html>
