thread::id
spaceship may be inconsistent with equalitySection: 32.4.3.2 [thread.thread.id] Status: New Submitter: Casey Carter Opened: 2021-01-26 Last modified: 2021-03-12
Priority: 3
View all other issues in [thread.thread.id].
View all issues with New status.
Discussion:
32.4.3.2 [thread.thread.id]/5-7 specify the behavior of ==
and <=>
for
std::thread::id
:
bool operator==(thread::id x, thread::id y) noexcept;-5- Returns:
true
only ifx
andy
represent the same thread of execution or neitherx
nory
represents a thread of execution.strong_ordering operator<=>(thread::id x, thread::id y) noexcept;-6- Let
-7- Returns:P(x, y)
be an unspecified total ordering overthread::id
as described in 25.8.strong_ordering::less
ifP(x, y)
istrue
. Otherwise,strong_ordering::greater
ifP(y, x)
istrue
. Otherwise,strong_ordering::equal
.
"Unspecified total ordering" provides too much freedom, since it does not require that !P(x, y)
holds when x
and y
both represent the same thread of execution or both represent no
thread of execution. A conforming implementation could return strong_ordering::equal
from
<=>
for a pair of thread::id
values for which ==
returns false
.
We should guarantee consistency of ==
and <=>
for thread::id
to
preserve sanity of the programming model.
[2021-03-12; Reflector poll]
Set priority to 3 following reflector poll.
Proposed resolution:
This wording is relative to N4878.
Modify 32.4.3.2 [thread.thread.id] as indicated:
strong_ordering operator<=>(thread::id x, thread::id y) noexcept;-6- Let
-7- Returns:P(x, y)
bean unspecifieda total ordering overthread::id
as described in 26.8 [alg.sorting], unspecified except thatP(x, y)
isfalse
whenx
andy
both represent the same thread of execution, or when neither represents a thread of execution.strong_ordering::less
ifP(x, y)
istrue
. Otherwise,strong_ordering::greater
ifP(y, x)
istrue
. Otherwise,strong_ordering::equal
.