[thread.thread.id]

# 32 Concurrency support library [[thread]](./#thread)

## 32.4 Threads [[thread.threads]](thread.threads#thread.thread.id)

### 32.4.3 Class thread [[thread.thread.class]](thread.thread.class#thread.thread.id)

#### 32.4.3.2 Class thread​::​id [thread.thread.id]

[ð](#lib:thread::id)

namespace std {class thread::id {public: id() noexcept; }; bool operator==(thread::id x, thread::id y) noexcept;
 strong_ordering operator<=>(thread::id x, thread::id y) noexcept; template<class charT, class traits> basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& out, thread::id id); template<class charT> struct formatter<thread::id, charT>; // hash supporttemplate<class T> struct hash; template<> struct hash<thread::id>;}

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1516)

An object of type thread​::​id provides a unique identifier for
each thread of execution and a single distinct value for all thread objects that do not represent a thread of
execution ([[thread.thread.class]](thread.thread.class "32.4.3 Class thread"))[.](#1.sentence-1)

Each thread of execution has an
associated thread​::​id object that is not equal to thethread​::​id object of any other thread of execution and that is not
equal to the thread​::​id object of any thread object that
does not represent threads of execution[.](#1.sentence-2)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1526)

The [*text representation*](#def:text_representation "32.4.3.2 Class thread​::​id [thread.thread.id]") for
the character type charT of an object of type thread​::​id is an unspecified sequence of charT such that,
for two objects of type thread​::​id x and y,
if x == y is true,
the thread​::​id objects have the same text representation, and
if x != y is true,
the thread​::​id objects have distinct text representations[.](#2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1536)

thread​::​id is a trivially copyable class ([[class.prop]](class.prop "11.2 Properties of classes"))[.](#3.sentence-1)

The library may reuse the value of a thread​::​id of a terminated thread that can no longer be joined[.](#3.sentence-2)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1540)

[*Note [1](#note-1)*:

Relational operators allow thread​::​id objects to be used as
keys in associative containers[.](#4.sentence-1)

â *end note*]

[ð](#lib:thread::id,constructor)

`id() noexcept;
`

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1552)

*Postconditions*: The constructed object does not represent a thread of execution[.](#5.sentence-1)

[ð](#lib:operator==,thread::id)

`bool operator==(thread::id x, thread::id y) noexcept;
`

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1563)

*Returns*: true only if x and y represent the same
thread of execution or neither x nor y represents a thread of
execution[.](#6.sentence-1)

[ð](#lib:operator%3c=%3e,thread::id)

`strong_ordering operator<=>(thread::id x, thread::id y) noexcept;
`

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1576)

Let P(x, y) be
an unspecified total ordering over thread​::​id as described in [[alg.sorting]](alg.sorting "26.8 Sorting and related operations")[.](#7.sentence-1)

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1581)

*Returns*: strong_ordering​::​less if P(x, y) is true[.](#8.sentence-1)

Otherwise, strong_ordering​::​greater if P(y, x) is true[.](#8.sentence-2)

Otherwise, strong_ordering​::​equal[.](#8.sentence-3)

[ð](#lib:operator%3c%3c,thread::id)

`template<class charT, class traits>
  basic_ostream<charT, traits>&
    operator<<(basic_ostream<charT, traits>& out, thread::id id);
`

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1597)

*Effects*: Inserts the text representation for charT of id intoout[.](#9.sentence-1)

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1602)

*Returns*: out[.](#10.sentence-1)

[ð](#lib:formatter,specializations,thread::id)

`template<class charT> struct formatter<thread::id, charT>;
`

[11](#11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1613)

formatter<thread​::​id, charT> interprets *format-spec* as a *thread-id-format-spec*[.](#11.sentence-1)

The syntax of format specifications is as follows:

thread-id-format-spec :  
fill-and-alignopt widthopt

[*Note [2](#note-2)*:

The productions *fill-and-align* and *width* are described in [[format.string.std]](format.string.std "28.5.2.2 Standard format specifiers")[.](#11.sentence-3)

â *end note*]

[12](#12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1628)

If the *align* option is omitted it defaults to >[.](#12.sentence-1)

[13](#13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1631)

A thread​::​id object is formatted by
writing its text representation for charT to the output
with additional padding and adjustments as specified by the format specifiers[.](#13.sentence-1)

[ð](#lib:hash,thread::id)

`template<> struct hash<thread::id>;
`

[14](#14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1643)

The specialization is enabled ([[unord.hash]](unord.hash "22.10.19 Class template hash"))[.](#14.sentence-1)
