This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

3516. thread::id spaceship may be inconsistent with equality

Section: 33.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:

33.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 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;

-6- Let P(x, y) be an unspecified total ordering over thread::id as described in 25.8.

-7- Returns: strong_ordering::less if P(x, y) is true. Otherwise, strong_ordering::greater if P(y, x) is true. 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.

  1. Modify 33.4.3.2 [thread.thread.id] as indicated:

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

    -6- Let P(x, y) be an unspecifieda total ordering over thread::id as described in 27.8 [alg.sorting], unspecified except that P(x, y) is false when x and y both represent the same thread of execution, or when neither represents a thread of execution.

    -7- Returns: strong_ordering::less if P(x, y) is true. Otherwise, strong_ordering::greater if P(y, x) is true. Otherwise, strong_ordering::equal.