1277. std::thread::id should be trivially copyable

Section: [thread.thread.id] Status: C++11 Submitter: Anthony Williams Opened: 2009-11-24 Last modified: 2016-01-28 10:19:27 UTC

Priority: Not Prioritized

View all other issues in [thread.thread.id].

View all issues with C++11 status.


The class definition of std::thread::id in N3000 is:

class thread::id {

Typically, I expect that the internal data members will either be pointers or integers, so that in practice the class will be trivially copyable. However, I don't think the current wording guarantees it, and I think it would be useful. In particular, I can see a use for std::atomic<std::thread::id> to allow a thread to claim ownership of a data structure atomicly, and std::atomic<T> requires that T is trivially copyable.

[ 2010-02-12 Moved to Tentatively Ready after 7 positive votes on c++std-lib. ]

Proposed resolution:

Add a new sentence to [thread.thread.id] p1:

1 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 (33.4.3 [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 std::thread object that does not represent threads of execution. The library may reuse the value of a thread::id of a terminated thread that can no longer be joined. thread::id shall be a trivially copyable class (11 [class]).