[patch] libstdc++/57060 cope with invalid thread IDs

Jonathan Wakely jwakely@redhat.com
Fri Dec 4 17:35:00 GMT 2015


This patch ensures that this_thread::get_id() returns a value that is
distinct from the "not a thread" value, and avoids undefined behaviour
in pthread_equal.

Previously programs using glibc but not linking to libpthread would
get the "not a thread" value for std::this_thread::get_id() in main.
We were also using pthread_equal() with the "not a thread" value,
which is undefined.

This change assumes that pthread_t is EqualityComparable, but we
already have to assume it's LessThanComparable and apparently that
works everywhere that std::thread is supported, so this should too.

If it fails then we can do something smarter like dispatch based on
whether __gthread_t is an EqualityComparable scalar type, but I'd
prefer to avoid that complexity if this simpler version works.

Tested powerpc64le-linux, committed to trunk.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 3678 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20151204/140893a3/attachment.bin>


More information about the Libstdc++ mailing list