32 Concurrency support library [thread]

32.4 Threads [thread.threads]

32.4.3 Class thread [thread.thread.class]

32.4.3.2 Class threadโ€‹::โ€‹id [thread.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 support template<class T> struct hash; template<> struct hash<thread::id>; }
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]).
Each thread of execution has an associated threadโ€‹::โ€‹id object that is not equal to the threadโ€‹::โ€‹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.
The text representation 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.
threadโ€‹::โ€‹id is a trivially copyable class ([class.prop]).
The library may reuse the value of a threadโ€‹::โ€‹id of a terminated thread that can no longer be joined.
[Noteย 1:โ€‚
Relational operators allow threadโ€‹::โ€‹id objects to be used as keys in associative containers.
โ€”ย end note]
id() noexcept;
Postconditions: The constructed object does not represent a thread of execution.
bool operator==(thread::id x, thread::id y) noexcept;
Returns: true only if x and y represent the same thread of execution or neither x nor y represents a thread of execution.
strong_ordering operator<=>(thread::id x, thread::id y) noexcept;
Let P(x, y) be an unspecified total ordering over threadโ€‹::โ€‹id as described in [alg.sorting].
Returns: strong_orderingโ€‹::โ€‹less if P(x, y) is true.
Otherwise, strong_orderingโ€‹::โ€‹greater if P(y, x) is true.
Otherwise, strong_orderingโ€‹::โ€‹equal.
template<class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& out, thread::id id);
Effects: Inserts the text representation for charT of id into out.
Returns: out.
template<class charT> struct formatter<thread::id, charT>;
formatter<threadโ€‹::โ€‹id, charT> interprets format-spec as a thread-id-format-spec.
The syntax of format specifications is as follows:
thread-id-format-specโ€‰:
fill-and-align width
[Noteย 2:โ€‚
The productions fill-and-align and width are described in [format.string.std].
โ€”ย end note]
If the align option is omitted it defaults to >.
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.
template<> struct hash<thread::id>;
The specialization is enabled ([unord.hash]).